473,569 Members | 2,845 Online
Bytes | Software Development & Data Engineering Community
+ 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 12821
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
3630
by: Casper JH Erasmus | last post by:
How do I save the contents of a TreeView to a XML Document?
3
10133
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 that. Im trying for about 3 hours but can't get it to work. Thank you!
13
9044
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 path "Users\Administrators\John Doe"? Thank you in advance! Andre Nogueira
8
14258
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 object in VB6. What is the equivalent of "Key" property of TreeView node in VB.NET? Has the property name "Key" has been changed to something else?...
6
4915
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. However, either it only add it to the root level or it only add it on level below, doesn't matter what I select. And in some case, I just get an...
2
22010
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
10
2337
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 top border. Is it possible to have more than 1 style at the same level (parent node) when using a SiteMap? I want it to appear something like...
6
11945
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 is under NodeA or NodeB. I can do this by splitting the selectednode.fullpath of the child node but there must be a better way. Can any kind soul...
0
7157
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 child rows and added the nodes with a columnname from each datarow. At the same time i have put in a tag at each treenode with a filter string and the...
0
3288
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. Provide following view properties to listview, through View menu a. Tile b. Icon
0
8119
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7668
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7964
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6281
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...
1
5509
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...
0
3653
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...
0
3637
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2111
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
1
1209
muto222
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.