How Can i Add Child Node Under Existing Node Using DataSet in windows programing

Posted by Shijohnjoseph under C# on 1/21/2011 | Points: 10 | Views : 2876 | Status : [Member] | Replies : 2
Hi Every Body ,

I am a beginner in windows programing , actually i have a database with student details having a column with different department names like mechanical electrical ,computer,civil like that , and i have a tree view with nodes named department name ,
on tree view node click i have to list down the student name as child node under the node filter with department ..
this is my task ..........please help me .....

am awaiting for a reply

"Personality has the power to open many doors, but character must keep them open"


Responses

Posted by: T.saravanan on: 1/21/2011 [Member] [MVP] Silver | Points: 25

Up
0
Down
Hi,

Refer the following Code.....
Here

trMainTree --> Your TreeView Control Name
dtDept --> Your Distinct Department details
dtName --> Based on Dept Students Name

private void AddDeptDetails()
{
for(int x=0; x < dtDept.Rows.Count; x++)
{
TreeNode trDept = new TreeNode();
trDept.Name = dtDept.Rows[x]["Name"].Tostring();
trDept.Text = dtDept.Rows[x]["Name"].Tostring();
//Pass the Department Name and get Student Name based on the dept in DataTable(dtName)
AddNameDetails(dtName, trDept);
trMainTree.Nodes.Add(trDept);
}
}

Private void AddNameDetails(DataTable dtName, TreeNode trDept)
{
for(int y=0; y < dtName.Rows.Count; y++)
{
TreeNode trName = new TreeNode();
trName.Name = dtName.Rows[y]["Name"].Tostring();
trName.Text = dtName.Rows[y]["Name"].Tostring();
trDept.Nodes.Add(trName);
}
}



Try this code..I think its useful to you...

Cheers :)


Thanks,
T.Saravanan

Shijohnjoseph, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Karthikanbarasan on: 1/22/2011 [Member] [Moderator] [Microsoft_MVP] [MVP] Silver | Points: 25

Up
0
Down
hi,

Check this link... It explains how to use the tree view control in win app

http://www.c-sharpcorner.com/UploadFile/prasadh/TreeViewControlInWinFormsPSD11182005235448PM/TreeViewControlInWinFormsPSD.aspx

Thanks
Karthik
www.f5Debug.net

Shijohnjoseph, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response