动态添加子节点如何添加子节点
我的主窗体上有一个树视图 我
的从主窗体到主窗体的代码如下
Buttonclick
StrNode = string.Empty;
StrNode = "Batch" + Append.Batchcnt.ToString() + "(" + strSelectedClassCode + ")";
frmmain.loadFromForm(StrNode, true, strSelectedClassCode);
在我的主窗体上我的代码如下
public void loadFromForm(string strNode, bool bResult, string strStandardClsCode)
{
if (Append.oldbatchcontrol != strNode)
{
if (tvwACH.SelectedNode.Text == "FileHeader")
{
tvwACH.SelectedNode.Nodes.Add(strNode);
}
if (tvwACH.SelectedNode.Text == "BatchHeader")
{
tvwACH.SelectedNode.Nodes.Add(strNode);// After this i have to add another node as a child to that added node and also if a node with particular name exists i would like to write the text with a count value appended
}
}
}
所以我的树视图应该如下
ACH
|->Some.txt
|->Fileheader
|->BatchHeader
|->Batch1
|->Entry1
|->Entry2 and so on // These two should be added dynamically after that Batch1
I am having a treeview on my main form
I have my code from a from to main form is as follows
Buttonclick
StrNode = string.Empty;
StrNode = "Batch" + Append.Batchcnt.ToString() + "(" + strSelectedClassCode + ")";
frmmain.loadFromForm(StrNode, true, strSelectedClassCode);
On my main form i have my code as follows
public void loadFromForm(string strNode, bool bResult, string strStandardClsCode)
{
if (Append.oldbatchcontrol != strNode)
{
if (tvwACH.SelectedNode.Text == "FileHeader")
{
tvwACH.SelectedNode.Nodes.Add(strNode);
}
if (tvwACH.SelectedNode.Text == "BatchHeader")
{
tvwACH.SelectedNode.Nodes.Add(strNode);// After this i have to add another node as a child to that added node and also if a node with particular name exists i would like to write the text with a count value appended
}
}
}
So that my treeview should be as follows
ACH
|->Some.txt
|->Fileheader
|->BatchHeader
|->Batch1
|->Entry1
|->Entry2 and so on // These two should be added dynamically after that Batch1
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用这个代替:
Use this instead :
您通常需要递归函数来构建树。例如:
此代码是一个粗略的指南,但它应该给您一个想法。
You usually need a recursive function to build a tree. For example:
This code is a rough guide, but it should give you an idea.