Winform underground and database associations are very common, the following code is used in the project, split from a table:
DataView DVTree;
Private Void InittreebyDataSet (TreenodeCollection NDS, String ParentID, DataSet DS)
{
Dvtree = new dataview ();
Treenode TempNode;
DVTree.table = ds.tables [0];
/ / Judgment whether the ParentServiceTypeID is NULL and generates different filtration conditions
IF (ParentID == "Isnull (ParentServiceTypeId, 'Null Column') = 'Null Column'")
{
Dvtree.rowfilter = ParentID;
}
Else
{
Dvtree.rowfilter = "ParentServiceTypeID = '" ParentID "'"
}
Foreach (DataRowView Drvtree In DVTree)
{
TempNode = New Treenode ();
TempNode.Text = drvtree ["name"]. TOSTRING ();
TempNode.tag = drvtree ["pkfieldvalue"]. TOSTRING ();
nds.add (tempnode);
// Recursive call
INITTREEBYDATASET (TempNode.Nodes, TempNode.tag.toT7tring (), DS);
}
}
Two related links:
"Application of tree structure in development",
Select the tree node and display it details