Hi All,
I want to implement the Tree View in visual C#,in such a way that I can select more than one node at a time, what should be the code.
Thanks
Hi All,
I want to implement the Tree View in visual C#,in such a way that I can select more than one node at a time, what should be the code.
Thanks
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Niradhip ChakrabortyPosted Jun 5, 2008, 7:33 AM
You should refer the code given by Scott. Incase you need further assistance you can refer the following URL.
http://www.codeproject.com/KB/tree/mwcontrols.aspx
http://www.codeproject.com/KB/tree/treeviewms.aspx
tomPosted Jun 5, 2008, 7:30 AM
I actually want to do it without checkboxes,for eg we can select multiple folders in windows by pressing ctrl+mouse click.
I my application I have to perform drag drop for multiple selected nodes of a tree.
How can this be implemented?
Thanks.
Scott LyslePosted Jun 5, 2008, 7:07 AM
You could use the checked property on the treeview and allow multiple selections based on the state of the checkbox on each node.
You could iterate through the treenodes to see which were checked (you'd really use recursion but here is an example that would iterate through two layers of nodes):
StringBuilder sb = new StringBuilder();
foreach (TreeNode t in treeView1.Nodes)
{
if (t.Checked == true)
sb.Append(t.Text + Environment.NewLine);
if (t.Nodes.Count > 0)
{
foreach (TreeNode tt in t.Nodes)
{
if (tt.Checked == true)
sb.Append(tt.Text + Environment.NewLine);
}
}
}
MessageBox.Show(sb.ToString(), "Checked Nodes");