473,780 Members | 2,258 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

windows tree view data binding from data base

5 New Member
hi every one..

i am binding data in a tree view using windows C# .. auctually i finished most of the code.. but i did't know how to proceed further .. i attached the code hear.. as well as it display the parent id.. insted of group_name ...


private void Form1_Load(obje ct sender, EventArgs e)
{
PopulateRootLev el();
}

private void PopulateRootLev el()
{
SqlConnection objConn = new SqlConnection(" Data Source=CDTECHPR O2\\SQLEXPRESS; Initial Catalog=Image;I ntegrated Security=True") ;
SqlCommand objCommand = new SqlCommand("sel ect ParentId,GroupN ame,(select count(*) FROM tree WHERE SubGroup=sc.Par entId) childnodecount FROM tree sc where SubGroup IS NULL", objConn);
SqlDataAdapter da = new SqlDataAdapter( objCommand);
DataTable dt = new DataTable();
da.Fill(dt);
PopulateNodes(d t, treeView1.Nodes );
}

private void PopulateNodes(D ataTable dt, TreeNodeCollect ion nodes)
{
int NodeIndex = 0;
foreach (DataRow dr in dt.Rows)
{
TreeNode tn = new TreeNode();
tn.Name = dr["GroupName"].ToString();
tn.Text = dr["ParentId"].ToString();
nodes.Add(tn);

if ((int)dr["childnodecount "] > 0)
{
NodeIndex++;
}
else
{
NodeIndex = 0;
}
}
}

private void treeView1_After Select(object sender, TreeViewEventAr gs e)
{
int s = int.Parse(e.Nod e.Text);
PopulateSubLeve l(s, e.Node);
}

private void PopulateSubLeve l(int parentid, TreeNode parentNode)
{
SqlConnection objConn = new SqlConnection(" Data Source=CDTECHPR O2\\SQLEXPRESS; Initial Catalog=Image;I ntegrated Security=True") ;
SqlCommand objCommand = new SqlCommand("sel ect ParentId,GroupN ame,(select count(*) FROM tree " + "WHERE SubGroup=sc.Par entId) childnodecount FROM tree sc where SubGroup=@SubGr oup", objConn);
objCommand.Para meters.Add("@Su bGroup", SqlDbType.Int). Value = parentid;
SqlDataAdapter da = new SqlDataAdapter( objCommand);
DataTable dt = new DataTable();
da.Fill(dt);
PopulateNodes(d t, parentNode.Node s);
}

private void treeView1_After Check(object sender, TreeViewEventAr gs e)
{
int s = int.Parse(e.Nod e.Text);
PopulateSubLeve l(s, e.Node);
}

the datadatse is

parentid groupname subgroup

11 tree1 Null
12 tree2 Null
13 node1 11
14 node2 12
15 newnode 13



any one can help me..

regards
jagatheesan.
Dec 27 '07 #1
1 1817
mzmishra
390 Recognized Expert Contributor
Your tn.Text = dr["ParentId"].ToString(); is pointing to Parentid,that why u r gettting parent id as displayed text
Dec 27 '07 #2

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

Similar topics

4
1774
by: dave | last post by:
I have an Access 97 application running quite happily in Windows 2000. If I upgrade a machine to Windows 2000 SP4 then I get an error in one area which is this - I use Automation to run an instance of Excel, into which I poke data and produce graphs. I use the exact method as given in an 'official' Microsoft help file called auto97.hlp The relevant lines of code are:
10
2529
by: dwok | last post by:
Does anyone know of a good article that discusses creating a "Tree View" control in ASP.NET? Or perhaps a Tree View Control that comes with source code? I have come across a lot of tree controls for ASP.NET however most of them are already compiled and don't come with source code. I am really just looking for an example on how to create my own Tree Control. Thanks a bunch.
2
1910
by: UJ | last post by:
I have an app that I've already written that works just great. It's a window's explorer like app for our data. Problem is, to build the treeview takes too long (30 secs and upward for less than 1000 records). And the database is only going to be getting bigger. Here's essentially what I do: Get three tables that are related (I don't make the relationship locally) Start stepping through table 1. Find all of the records from table 2...
5
1526
by: Ronald S. Cook | last post by:
I need ideas on how to best design a Windows form for my particular situation. On a cattle feeding yard there will be between about 300 and 600 pens. On my "Pen Feeding Sequence" form, I want the user to be able to setup and maintain the order in which the pens should be fed (ultimately in the Pen table is a column named Sequence that gets an interger value). So on the form...
0
1140
by: Rohit111111 | last post by:
Hello all, I have a tree view control that will populate data upto n level,on selection of a node i am binding a datagrid on the same page,now i have to expand that node which i have selected,which is not expanded currently,after selecting a node data grid will be bind correctly but my tree will collasp all node i have to exapnd only that node which i have selected please help
1
2177
by: perspolis | last post by:
Hi all I'm looking for a Combobox that displays tree. Does anyone has a source code for that??? thanks in advance
1
4614
by: sureshpuli | last post by:
currently there is a custom paging option .. so everytime we are retreiving 10 records from data base to front end and showing in data grid. i kept this 10 records in view state. and iam updating the records, and adding the new records . but now i have to show the total records from the data base ..and i have to show..but while updating and adding the records it is giving error like Failed to load viewstate. The control tree into...
0
2044
by: choukse | last post by:
Hi All, I am trying to bind to ADAM instance with a windows user through JNDI and it keeps failing. My ADAM and AD is running on same Windows 2k3 server. But, through LDP I am able to bind with the same windows user successfully and browse through the entire tree successfully. The error is as below
12
11111
by: raylopez99 | last post by:
Keywords: scope resolution, passing classes between parent and child forms, parameter constructor method, normal constructor, default constructor, forward reference, sharing classes between forms. Here is a newbie mistake that I found myself doing (as a newbie), and that even a master programmer, the guru of this forum, Jon Skeet, missed! (He knows this I'm sure, but just didn't think this was my problem; LOL, I am needling him) If...
0
10306
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10075
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
9931
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7485
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
6727
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
5373
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
5504
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4037
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
2869
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.