473,395 Members | 1,393 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

windows tree view data binding from data base

5
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(object sender, EventArgs e)
{
PopulateRootLevel();
}

private void PopulateRootLevel()
{
SqlConnection objConn = new SqlConnection("Data Source=CDTECHPRO2\\SQLEXPRESS;Initial Catalog=Image;Integrated Security=True");
SqlCommand objCommand = new SqlCommand("select ParentId,GroupName,(select count(*) FROM tree WHERE SubGroup=sc.ParentId) childnodecount FROM tree sc where SubGroup IS NULL", objConn);
SqlDataAdapter da = new SqlDataAdapter(objCommand);
DataTable dt = new DataTable();
da.Fill(dt);
PopulateNodes(dt, treeView1.Nodes);
}

private void PopulateNodes(DataTable dt, TreeNodeCollection 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_AfterSelect(object sender, TreeViewEventArgs e)
{
int s = int.Parse(e.Node.Text);
PopulateSubLevel(s, e.Node);
}

private void PopulateSubLevel(int parentid, TreeNode parentNode)
{
SqlConnection objConn = new SqlConnection("Data Source=CDTECHPRO2\\SQLEXPRESS;Initial Catalog=Image;Integrated Security=True");
SqlCommand objCommand = new SqlCommand("select ParentId,GroupName,(select count(*) FROM tree " + "WHERE SubGroup=sc.ParentId) childnodecount FROM tree sc where SubGroup=@SubGroup", objConn);
objCommand.Parameters.Add("@SubGroup", SqlDbType.Int).Value = parentid;
SqlDataAdapter da = new SqlDataAdapter(objCommand);
DataTable dt = new DataTable();
da.Fill(dt);
PopulateNodes(dt, parentNode.Nodes);
}

private void treeView1_AfterCheck(object sender, TreeViewEventArgs e)
{
int s = int.Parse(e.Node.Text);
PopulateSubLevel(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 1798
mzmishra
390 Expert 256MB
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
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...
10
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...
2
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...
5
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...
0
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...
1
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
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...
0
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...
12
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....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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,...
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
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...

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.