Treeview根节点在子节点路径之前持续 [英] Treeview root node to last before child node path
问题描述
D1
1____D4
1 1_____D5
1 1 1_____7
1 1 1_____D8
1 1
1 1_____D6
1 1 1_____D9
1 1
1 1_____7
1
D2
1____D12
1 1_____D10
1 1_____D11
1
1_____D15
1 1____D16
1 1____D17
D3
1_____12
1_____13
Hai给所有人..
这是我想要的树视图的例子路径
即out put shoud必须喜欢这个...
D1 // D4 // D5 // D6 // D7
D1 // D4 // D6 // D9
D1 // D4 // D7
D2 // D12 // D10 / D11
D2 // D15 // D16 // D17
D3 // D12 // D13
这是必须的...
任何人都可以帮助我....
我假设你在谈论WinFormsTreeView
?
在这种情况下,试试这样的事情; < br $> b $ b
私人 string GetPath(TreeNode节点)
{
string path = ;
for (TreeNode iterator = node; iterator!= null ; iterator = iterator.Parent)
{
path = String .Format( {0} // {1},iterator.Name,path);
}
返回路径;
}
private void FindPaths(TreeNodeCollection节点,
IDictionary< TreeNode,string> paths)
{
foreach (节点中的TreeNode节点)
{
if (node.Nodes.Count == 0 )
paths [node] = GetPath(node);
else
FindPaths(node.Nodes,paths);
}
}
私有 void some_click_event( object sender,TreeViewEventArgs e)
{
IDictionary< TreeNode,string> paths = new 字典< TreeNode,string>();
FindPaths(treeView.Nodes,paths);
}
路径
字典将包含所有路径他们的叶子节点是关键。
希望这会有所帮助,
Fredrik
为了获得D1 // D4 // D5 // D6 // D7
用户此代码:[TreeView名称] .PathSeparator =//
就是这样。
D1
1____D4
1 1_____D5
1 1 1_____D7
1 1 1_____D8
1 1
1 1_____D6
1 1 1_____D9
1 1
1 1_____D7
1
D2
1____D12
1 1_____D10
1 1_____D11
1
1_____D15
1 1____D16
1 1____D17
D3
1_____D12
1_____D13
Hai to all..
this is the example of treeview now i want path
i.e out put shoud have to like this...
D1//D4//D5//D6//D7
D1//D4//D6//D9
D1//D4//D7
D2//D12//D10/D11
D2//D15//D16//D17
D3//D12//D13
This is required out put...
can anybody please help me....
I am assuming you're talking about WinFormsTreeView
?
In that case, try something like this;
private string GetPath(TreeNode node) { string path = ""; for (TreeNode iterator = node; iterator != null; iterator = iterator.Parent) { path = String.Format("{0}//{1}", iterator.Name, path); } return path; } private void FindPaths(TreeNodeCollection nodes, IDictionary<TreeNode, string> paths) { foreach (TreeNode node in nodes) { if (node.Nodes.Count == 0) paths[node] = GetPath(node); else FindPaths(node.Nodes, paths); } } private void some_click_event(object sender, TreeViewEventArgs e) { IDictionary<TreeNode, string> paths = new Dictionary<TreeNode, string>(); FindPaths(treeView.Nodes, paths); }
Thepaths
dictionary will contain all the paths with their leaf node as key.
Hope this helps,
Fredrik
In order to get "D1//D4//D5//D6//D7"
User this code : [TreeView name].PathSeparator = "//"
thats it'.
这篇关于Treeview根节点在子节点路径之前持续的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!