Thanks for the reply. Actually while debugging the code I found there
was a call to a function in SQL Server which was written by someone
else and that was returning improper number of nodes for that specific
parent id.

As for your suggestion, I just wanted to let you know that the code I
provided was just a snippet of the function. I have taken care to loop
through till whatever level the nodes are.

Thanks though.

Appreciate your answer :)

On Mar 15, 11:26 am, Stefan Brandt <[email protected]> wrote:
> You are only adding root nodes and sub nodes which parent are root
> node. In your method that adds your sub nodes (level 2 nodes)->you
> must call recursively your method or some other method that adds your
> sub node children.
>
> For Example:
>
> 1) fetch root nodes (for example every node which ParentID==NULL) and
> add them to the tree
> 2) call method that collects sub nodes
>
> PopulateTreeView(null);
> ...
> ...
>
> private void PopulateTreeView(int? parentId)
> {
> var filteredItems = masterList.Where(item => item.ParentID ==
> parentId);
>
> foreach (var i in filteredItems.ToList())
> {
> /*
> Add sub node to the tree
> .
> .
> I BELIEVE THAT THE FOLLOWING THING IS WHAT ARE MISSING:
> and add sub node children also...
> call itself PopulateTreeView(i.ID); or some other method
> */
>
> }
>
> On Mar 14, 6:03 pm, S <[email protected]> wrote:
>
>
>
>
>
>
>
> > Hello all -- I am facing a weird problem with my object that I create
> > at application start up. This object holds the data from the database
> > which is referenced throughout the application.
>
> > So the table contents following structure
>
> > ID , ParentID , Name, Value
>
> > First few values form the root of the structure. In my logic first I
> > create the root nodes and then with another query I get all the values
> > which are not the root and using the root values I create a list from
> > the non-root nodes.
>
> > For a specific root values deep in the tree I have 5 values but only 2
> > are fetched from that list. I have tested in other parts of the code
> > to see if only 2 values are returned for that node but it returns the
> > correct number (just for the test and not used anywhere). This issue
> > occurs only when I am actually building the tree. I fail to understand
> > why only for a specific value it returns incorrect number of children.
>
> > Any thoughts ?
>
> > var getChildren = (from mL in masterList
> >                                where mL.ParentID == parent.ID
> >                                orderby mL.ID
> >                                select new Category()
> >                                           {
> >                                               ID = mL.ID,
> >                                               Name = mL.Name,
> >                                               ParentID = mL.ParentID,
> >                                               Parent = parent,
> >                                               Level = parent.Level +
> > 1 ,
> >                                               Value = mL.Value,
> >                                               ETFCount = mL.ETFCount
> >                                           }
> >                               ).ToList();
>
> > Above is the code that is used to create the tree (this is a part of
> > recursive code in the function).

-- 
You received this message because you are subscribed to the Google
Groups "DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML
Web Services,.NET Remoting" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/dotnetdevelopment?hl=en?hl=en
or visit the group website at http://megasolutions.net

Reply via email to