473,473 Members | 2,114 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

C# Treeview child nodes

91 New Member
I am trying to add child nodes based on database query in which the users in the database are a part of the parent node. Here is my code.

Expand|Select|Wrap|Line Numbers
  1. private void GetUsersByGroup()
  2.         {
  3.             //Setup query
  4.             MySqlCommand cmdDatabase = new MySqlCommand("SELECT group_name FROM prov_groups WHERE group_name!='--None--';", conDatabase);
  5.  
  6.             cmdDatabase.ExecuteNonQuery();
  7.             MySqlDataReader myReader;
  8.             // Get data from query and send to tree view
  9.             myReader = cmdDatabase.ExecuteReader();
  10.             while (myReader.Read())
  11.             {
  12.  
  13.                 treeUsers.Nodes.Add(myReader.GetString(0));
  14.             }
  15.             myReader.Close();
  16.             int groupNodeCount = treeUsers.GetNodeCount();
  17.             for (int i = 0; i <= groupNodeCount; i++)
  18.             {
  19.                 cmdDatabase = "SELECT Name FROM tsms LEFT JOIN prov_groups ON (tsms.Group = prov_groups.gid AND prov_groups.name='"+treeUsers.Nodes[i].Text.ToString()+"');";
  20.                 cmdDatabase.ExecuteNonQuery();
  21.                 myReader = cmdDatabase.ExecuteReader();
  22.                 while (myReader.Read())
  23.                 {
  24.                     // ADD CHILD NODES HERE
  25.                 }
  26.                 myReader.Close();
  27.             }
I'm having trouble adding the child nodes to the parent nodes that are already in the treeview. Can someone lend a helping hand on this?

Thanks in advance.
May 21 '08 #1
2 12809
Plater
7,872 Recognized Expert Expert
Add them as a new treenode to the current treenode?
Expand|Select|Wrap|Line Numbers
  1. treeUsers.Nodes[i].Nodes.Add("Some Value or something")
  2.  
May 21 '08 #2
arggg
91 New Member
Add them as a new treenode to the current treenode?
Expand|Select|Wrap|Line Numbers
  1. treeUsers.Nodes[i].Nodes.Add("Some Value or something")
  2.  
AHHHH i was forgetting the .Nodes after Nodes[i]. Let me try that. Thanks for the reply
May 21 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Casper JH Erasmus | last post by:
How do I save the contents of a TreeView to a XML Document?
3
by: Jan Wrage | last post by:
Hi! I would like to implement a treeview in my existing application. It should show my entire Active-Directory structure, i.e. all Groups, Containers and OUs. Could somebody help me with...
13
by: André Nogueira | last post by:
Hi there. I know you can view a node's fullpath property, but is it posible to select a node using its path? Like, tell the treeview that the node that should be selected is the node with the...
8
by: Don Wash | last post by:
Hi There! I'm using VB.NET to create a TreeView application and unfortunately I could not find "Key" property in Node items of the TreeView. We used to have "Key" property in TreeView node...
6
by: L.M | last post by:
Hello, I knew how to use the treeview under VB6. After migrating to .NET, well, I'm lost. I try to add a new node, either to the same level or as a child to a selected node in the treeview....
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. ...
10
by: p3t3r | last post by:
I have a treeview sourced from a SiteMap. I want to use 2 different CSS styles for the root level nodes. The topmost root node should not have a top border, all the other root nodes should have a...
6
by: xla76 | last post by:
I have a simple treeview (treeview1) to which I have added two nodes (nodeA and nodeB) which have n levels of child nodes. What I want is to be able to identify whether the child node I select...
0
by: Dennis Francek | last post by:
Hello I have populated a treeview from my dataset and by clicking in the treeview i want to get the corresponding table shown in a datagridview. Ive managed this by looking at each DataRow and...
0
by: divya1949 | last post by:
Create a windows c# application which will Read a xml file and populate nodes in the treeview. 1 On selection of treenode display the child nodes of that node in listview control 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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...
1
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.