How to add items in tree view? For one DataRow, it contains parent item as one column and the rest columns are child nodes. Row structure is as follow.
Table - Person
column1 - SSN (text)
column2 - Name (text)
column3 - Age (int)
column4 - country (text)
column5 - height (double)
When you click/expand Name, it looks like below.
(-) Name
- Age
- Country
- Height
Each row will be displayed like above TreeView. How to populate this in TreeView? 3 columns in the row are child node of Name column (parent node). I am using C# and .Net 4.5 and Winform application only. I managed to connect to database already. Only need to populate TreeView with DataRowCollection.
Here is sample code trying to achieve the above idea.
private void FillDataInTree(DataRowCollection rows)
{
foreach(DataRow r in rows)
{
TreeNode[] cNodes = new TreeNode[3];
for(int i=0; i<3; i++)
{
cNodes[i].Text = r[i + 1].ToString();
}
TreeNode node = new TreeNode(r["pName"].ToString(), cNodes);
playerTreeView.Nodes.Add(node);
//playerTreeView.Nodes
}
}