Solved

TreeView Control in C#

Posted on 2006-06-30
1
258 Views
Last Modified: 2010-04-16

Hi all,

I would like to know how to access all the selected nodes in a tree view control in C#. I have tree with some nodes. I select some of them by using control key, but I am having trouble in my c# program to get access to all the selected tree nodes. It seems like I can only select one  node at a time.

How do I get around this problem ??

Thank you for your help in advance.


Ramesh
0
Comment
Question by:Ramesh4u
1 Comment
 
LVL 5

Accepted Solution

by:
aaronfeng earned 50 total points
ID: 17022694
Yes, you are correct for Winform.  You can not retrieve all selected nodes at once, only one at a time.  You will have to traverse all the nodes in order to find all the selected nodes.  In the past, I wrapped the TreeView control, so I can add this functionality in one place; however, you can just create a function to do it for you.

You would do something like this:

private void FindAllCheckedNodes(List<TreeNode> outputNodes, TreeNodeCollection parentNodes) {
  foreach (TreeNode node in parentNodes) {
    if (node.SelectedNode) {
      outputNodes.Add(node);
    }
    FindAllCheckedNodes(outputNodes, node.Nodes);
  }
}

outputNodes will contain all the selected nodes when the function is done running.  You will pass in the root node as the second argument.

Cheers,

Aaron
http://geekswithblogs.net/afeng/
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question