Solved

Create a TreeView using C#

Posted on 2008-06-20
2
1,020 Views
Last Modified: 2008-06-21
I need some help with a C# problem. I have a database that has three tables in it:

ServerStatus
Server
Database

What I want to do is create a TreeView that looks like this:

- Server Status
  - Server
    - Database

eg.

- Online
  - ApplicationServer20
    - AdventureWorks
    - Pubs
    - Northwind
+ Offline
+ Shutdown

Does anyone know how I can implement this?
0
Comment
Question by:computerstreber
2 Comments
 
LVL 16

Assisted Solution

by:CuteBug
CuteBug earned 200 total points
ID: 21836044
0
 
LVL 13

Accepted Solution

by:
sm394 earned 300 total points
ID: 21837648
you can add nodes in tree after getting result set from you query like
//--------------------------------------------------------------
foreach (DataRow row in ds.Tables[0].Rows)
                {
                           TreeNode newNode = new TreeNode(row["Column_NAME"].ToString());
                            treeView1.Nodes.Add(newNode);
                     }//end for
//--------------------------------------------------------------------
then you can add further child nodes through Recursive function  
OR
on node click event i.e.
treeView1.SelectedNode.Nodes.Add(newNode);

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

910 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now