473,793 Members | 2,810 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Chec kBoxes = true;
foreach (TreeNode node in treeGroups)
{
if (node.Nodes.Cou nt == 0)
TreeViewEx.AddC heckBoxToNode(n ode);
else
TreeViewEx.Remo veCheckBoxFromN ode(node);
}
Nov 16 '05 #1
1 6270
Trevor,

Try something like this:

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

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

private void SetupTreeView(T reeNode parentNode)
{
foreach( TreeNode node in parentNode.Node s )
{
SetupTreeView(n ode);

if( node.Nodes.Coun t == 0 )
TreeViewEx.AddC heckBoxToNode(n ode);
else
TreeViewEx.Remo veCheckBoxFromN ode(node);
}
}
"Trevor" <tr****@spam.co m> 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.Chec kBoxes = true;
foreach (TreeNode node in treeGroups)
{
if (node.Nodes.Cou nt == 0)
TreeViewEx.AddC heckBoxToNode(n ode);
else
TreeViewEx.Remo veCheckBoxFromN ode(node);
}

Nov 16 '05 #2

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

Similar topics

0
1394
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 objective is to let the user select the folders and files using Checkboxes. Problems so far are: 1- When a TreeNode is collapsed and expanded again, it looses its Checked state. Can this be avoided? 2- There appears to be no way to set the checked...
2
1787
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 directories. Thanks.
2
22062
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. Thanks in advance for any help, Jack
1
3318
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 contains HTML, then the tooltip shows the raw HTML, which is unacceptable to users. Is there any way to block the tooltips from displaying this HTML?
0
1252
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 parent node ,the checkboxes for all the child nodes must get checked---this functionality should be implemented on the client side,using javascript. can i postback the page every time i check a checkbox?
0
5442
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"> function postbackOnCheck() { var o = window.event.srcElement; if (o.tagName == 'INPUT' && o.type == 'checkbox' &&
0
1252
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 checkboxes, but i only want certain nodes to have checkbox. Is there any way to do that? Thanks, your help would be greatly appreciated.
1
3771
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 has no tri state capability. I googled for this and suepried to find this is lacking however they were mostly quite old links,
1
2050
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 only want the event to run some code only if the user clicks the check box. This means that if the user clicks the "text" of the TreeNode, it will do nothing. However, if the user clicks the checkbox, which is next to the "text" the code will...
0
9671
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9518
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9035
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7538
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6777
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5436
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5560
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4112
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2919
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.