473,386 Members | 1,758 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Selective checkboxes in TreeView

How can I recursively loop through _every_ TreeNode in a TreeView using
C#? The CheckBoxes property enables checkboxes for all TreeNodes. I
only want checkboxes on TreeNodes that have 0 child nodes. I don't know
how many levels deep the TreeView will be. I have the checkboxes part
under control but my code only loops through the root nodes of my
TreeView.

// My incorrect code

treeGroups.CheckBoxes = true;
foreach (TreeNode node in treeGroups)
{
if (node.Nodes.Count == 0)
TreeViewEx.AddCheckBoxToNode(node);
else
TreeViewEx.RemoveCheckBoxFromNode(node);
}
Nov 16 '05 #1
1 6249
Trevor,

Try something like this:

public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

foreach( TreeNode node in treeView1.Nodes )
{
SetupTreeView(node);
}
}

private void SetupTreeView(TreeNode parentNode)
{
foreach( TreeNode node in parentNode.Nodes )
{
SetupTreeView(node);

if( node.Nodes.Count == 0 )
TreeViewEx.AddCheckBoxToNode(node);
else
TreeViewEx.RemoveCheckBoxFromNode(node);
}
}
"Trevor" <tr****@spam.com> wrote in message
news:Xn***************************@207.46.248.16.. .
How can I recursively loop through _every_ TreeNode in a TreeView using
C#? The CheckBoxes property enables checkboxes for all TreeNodes. I
only want checkboxes on TreeNodes that have 0 child nodes. I don't know
how many levels deep the TreeView will be. I have the checkboxes part
under control but my code only loops through the root nodes of my
TreeView.

// My incorrect code

treeGroups.CheckBoxes = true;
foreach (TreeNode node in treeGroups)
{
if (node.Nodes.Count == 0)
TreeViewEx.AddCheckBoxToNode(node);
else
TreeViewEx.RemoveCheckBoxFromNode(node);
}

Nov 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Garet | last post by:
Hi Everyone, I'm having some trouble working with a TreeView with checkboxes. It is being used in a DotNet (1.1) Desktop Windows Application for file selection, together with a ListView. The...
2
by: Michael A. Covington | last post by:
Can somebody point me to an example of how to put checkboxes on a treeview? I want to set up something that is very much like the way tape backup programs let you select a set of files and/or...
2
by: Jack | last post by:
Hello, I am trying use a TreeView with checkboxes. I would like to check more than one node and allow all child nodes of selected nodes to be checked or unchecked with the parent is checked. ...
1
by: Mark | last post by:
Hello, I am using the new TreeView in ASP.Net 2.0. I am using its PopulateOnDemand feature. The problem is that the treeviews +/- images, and any checkboxes, have the tooltip set. If the node...
0
by: pushpi | last post by:
Hi, i'm using the Treeview contol in asp.net 2.0 (present in VS2005 toolbox). i'm having checkboxes for all the nodes in the treeview.All i want to have is that On Checking a checkbox for a...
0
by: Dmitry Perets | last post by:
Hello, There is a known problem with TreeView checkboxes in ASP.NET: they can't do AutoPostBack. So I've solved this problem like this: <script language="javascript" type="text/javascript"> ...
0
by: Wudi008 | last post by:
Hi, I am using C#, I have a treeView in my windows.form , I want to give checkboxes for some nodes in the treeView but not all of them. If i do treeView.checkbox = true, all the nodes would have...
1
by: colin | last post by:
Hi, I have a simple treeview, I want to put tri state checkboxes. I thought this would be standard, TreeViewNode has checkboxes, and checkboxes have tri state, but the TreeViewNode checkbox...
1
by: =?Utf-8?B?VHJlY2l1cw==?= | last post by:
Hello, Newsgroupians: A quick question regarding checkboxes and a treeview. I have a treeview that has the property CheckBoxes. However, I'm also trying to handle the event NodeMouseClick. I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.