How to load dataset tables in treenode?
If user wants to create treenode which has different tables alongwith treenode column names and its datatype then this code will be used. You can also add gridview control in your form and add datatable as its datasource to get all the data under a particular column.
Method description:
myRoot represents root node which is "DATASET TABLES". mytblchild represent table name.
mycolchild represents column name and myDatatypechild represents datatype of column.
private void display_data_from_datasetTables_To_Treenode()
{
lstDataset.LabelEdit = false;
lstDataset.ImageList = imageList1;
TreeNode myRoot = new TreeNode("DATASET TABLES", 0, 0);
lstDataset.Nodes.Add(myRoot);
TreeNode mytblchild;
foreach (DataTable dtTable in ds.Tables)
{
mytblchild = new TreeNode(dtTable.TableName.ToUpper(), 1, 2);
TreeNode mycolchild, myDatatypechild;
foreach (DataColumn dcColumn in dtTable.Columns)
{
mycolchild = new TreeNode(dcColumn.ColumnName.ToUpper(), 3, 3);
myDatatypechild = new TreeNode(dcColumn.DataType.ToString(), 4, 4);
mycolchild.Nodes.Add(myDatatypechild);
mytblchild.Nodes.Add(mycolchild);
}
myRoot.Nodes.Add(mytblchild);
}
lstDataset.LabelEdit = true;
}