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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Scott LysleRank #49 · 31K reputationPosted Jun 5, 2008, 3:07 AM EDT
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");
tom8 reputationPosted Jun 5, 2008, 3:30 AM EDT
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.
Niradhip ChakrabortyRank #429 · 5.8K reputationPosted Jun 5, 2008, 3:33 AM EDT
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