我有一个树视图,它正确地填充父,子和大子节点。
-Root 1
|
|___________ Child 1
|___________ Child 2
|___________ Child 3
- Root 2
|___________ Child A
|___________ Child B
| |___________ Grand Child 1
| |___________ Grand Child 2
|
|___________ Child C
现在我想在每个父节点之后创建一个Create按钮/链接,以创建一个新的子元素或者子元素。
-Root 1
|___ **Create New Child**
|
|___________ Child 1
|___________ Child 2
|___________ Child 3
- Root 2
|____ **Create New Child**
|__________ Child A
|___________ Child B
| |__ **Create New Child**
| |________ Grand Child 1
| |___________ Grand Child 2
|
|___________ Child C
因此,当我点击Create New Child时,它会打开一个空白表单,我可以在其中填写信息并创建一个新孩子,现在我可以通过点击任何节点来编辑节点信息。
这是我创建节点的代码。
#region ROOT NODE
DataTable dtInstitute = dsResult.Tables[0]; //dsResult contains two columns refValues, refGroupId , I have separate code for that
List<Button> buttons = new List<Button>();
foreach (DataRow row in dtInstitute.Rows)
{
TreeNode child = new TreeNode
{
Text = row["refValues"].ToString(),
Value = row["refGroupId"].ToString()
};
AddChild(child);
treeCatalogManager.Nodes.Add(child);
}
treeCatalogManager.CollapseAll();
#endregion
private void AddChild(TreeNode child)
{
#region ADD CHILD
DataTable dtChild = dsChildResult.Tables[0]; //dsChildResult contains two columns refValues, refGroupId , I have separate code for that and able to populate here
foreach (DataRow row in dtChild.Rows)
{
TreeNode nChild = new TreeNode
{
Text = row["refValues"].ToString(),
Value = row["refGroupId"].ToString()
};
AddChild(nChild);
child.ChildNodes.Add(nChild);
}
#endregion
}