Retrieve a specific node from treeNode

Joined
Oct 27, 2008
Messages
2
Reaction score
0
Hi,
I have a treeNode I fill in thorugh dataset:
Code:
user_hier = new DataSet();

            user_hier.Tables.Add(new DataTable("Users"));
            
            /*DataColumn c = new DataColumn("DisplayName", typeof(string));
            user_hier.Tables[0].Columns.Add(c);  */
            DataRow row1;
            DataRow row2;
            for (int i = 1; i < 10; i++)
            {
                row1 = user_hier.Tables[0].NewRow();
                row1["DisplayName"] = "Group" + i;
                row1["ParentId"] = -1;
                row1["Id"] = i;
                user_hier.Tables[0].Rows.Add(row1);

                for (int j = 1; j < 10; j++)
                {
                    row2 = user_hier.Tables[0].NewRow();
                    row2["DisplayName"] = "user" + i + "_" + j;
                    row2["ParentId"] = i;
                    row2["Id"] = j;
                    user_hier.Tables[0].Rows.Add(row2);
                }
            }






            if (user_hier.Tables.Count > 0)
            {
                foreach (DataRow row in user_hier.Tables[0].Rows)
                {
                    if ((int)row["ParentId"] == -1)
                    {
                        TreeNode NewNode = new
                           TreeNode(row["DisplayName"].ToString(),
                           row["Id"].ToString());
                        NewNode.PopulateOnDemand = true;
                        NewNode.SelectAction = TreeNodeSelectAction.Expand;
                        node.ChildNodes.Add(NewNode);
                    }
                }
            }

            


            if (user_hier.Tables.Count > 0)
            {
                foreach (DataRow row in user_hier.Tables[0].Rows)
                {
                    if ((int)row["ParentId"] != -1)
                    {
                        int parentId = (int)row["ParentId"];
                        TreeNode parentNode = tvUsers.FindNode(parentId.ToString());
                        if (parentNode != null)
                            PopulateUsers(parentNode);
                        else
                            throw new Exception("User was added to a non - existing group");
                    }
                }
            }
        }

I want to be able to retrieve a node by it's "Id" programmatically, and send it to PopulateUsers(parentNode). Currently this returning null, probably because I need to send a PATH (what is this property?).

Is there a way to retrieve a node by a user-specified attribute?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,772
Messages
2,569,593
Members
45,112
Latest member
VinayKumar Nevatia
Top