Hi,
I have a treeNode I fill in thorugh dataset:
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?
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?