是否有可能得到孩子节点的一个编程得到选择 [英] Is it possible to get one of the child node get selected programatically
本文介绍了是否有可能得到孩子节点的一个编程得到选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想选择我的树视图的子节点之一得到编程选择。我的树视图是在运行时遵循
根
| - > A.TXT(我想选择在我的应用程序)做一些迭代后该节点
| - >儿童(即使我选择这个节点做一些操作我想选择只喜欢上面的一个,如果存在子节点的n个我会喜欢选择与扩展名为.txt)
节点
我写了下面的代码,它工作正常但有一点我是无法做到这一点任何一个可以帮助
这是我的代码
如果(tvwACH.Nodes.Count!= 0)
{
// tvwACH.ExpandAll();
树节点TN;
TN = tvwACH.Nodes [0];
tvwACH.ExpandAll();
如果(tn.Nodes.Count!= 0)
{
TN = tn.Nodes [0];
}
如果(tn.Tag.ToString()==3)
{
如果(tvwACH.SelectedNode.Parent!= NULL)
{
tn.Parent.Expand();
tvwACH.SelectedNode = TN;
}
}
}
我最后的TreeView的是如下
根
| - > Some.txt
| - >儿童
| - >辅助子
| - >儿童(用于subchild)//这之后,我不会有任何的节点,所以我的代码工作长达辅助子,但如果我点击subchild后过了一会儿加了一些东西,我不能选择我meeded节点,因为它没有节点的任何一个可以帮助我,请
解决方案
Atlast我得到的答案
树节点TvNode = tvwACH.SelectedNode.Parent;
,而(TvNode!= NULL)
{
如果(TvNode.Text.EndsWith(TXT,真实,System.Globalization.CultureInfo.InvariantCulture))
{
tvwACH.SelectedNode = TvNode;
TvNode = NULL;
}
,否则
TvNode = TvNode.Parent;
}
I would like to select one of the child node of my treeview get selected programatically. My treeview is as follow at run time
Root
|->A.txt(I would like to select this node after doing some iteration in my application)
|->Child(Even if i select this node and do some operations i would like to select the above one only like that if n number of child nodes exists i would like to select the node that was with .txt extension)
I have written the following code it works fine but at one point i am unable to do this can any one help
This is my code
if (tvwACH.Nodes.Count != 0)
{
// tvwACH.ExpandAll();
TreeNode tn;
tn = tvwACH.Nodes[0];
tvwACH.ExpandAll();
if (tn.Nodes.Count != 0)
{
tn = tn.Nodes[0];
}
if (tn.Tag.ToString() == "3")
{
if (tvwACH.SelectedNode.Parent != null)
{
tn.Parent.Expand();
tvwACH.SelectedNode = tn;
}
}
}
My final treeview is as follows
Root
|->Some.txt
|->Child
|->Sub Child
|->Child (for subchild) // After this i will not have any nodes so my code works up to Sub Child but if i added some thing after clicking Child after subchild i am unable to select the node i meeded as it has no nodes can any one help me out please
解决方案
Atlast i got the answer
TreeNode TvNode = tvwACH.SelectedNode.Parent;
while (TvNode != null)
{
if (TvNode.Text.EndsWith(".txt", true, System.Globalization.CultureInfo.InvariantCulture))
{
tvwACH.SelectedNode = TvNode;
TvNode = null;
}
else
TvNode = TvNode.Parent;
}
这篇关于是否有可能得到孩子节点的一个编程得到选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文