Current selected item:
Add top-level nodes: ("Key", "Text")
Add nodes of the same level: ("Key", "Text")
Add child nodes: ("Key", "Text")
Expand all: ()
Collapse all: ()
Reset TreeView
The database table structure is: ID Type Name Parent ID
private void loadTreeView()
{
this.Product Category (superCargoDataSet1.Product Category);
DataTable table = superCargoDataSet1. Product category;
DataRow[] row = ("Parent ID=0");
foreach (DataRow r in row)
{
TreeNode node = Product category (r["ID"].ToString(), r["type name"].ToString());
recursionShow(node, r["ID"].ToString());
}
}
private void recursionShow(TreeNode nodes, string id)
{
DataTable table = superCargoDataSet1. Product category;
DataRow[] row = ("parent ID=" + id);
if (row != null)
{
foreach (DataRow r in row)
{
TreeNode node = (r["ID"].ToString(), r["type name"].ToString());
recursionShow(node, r["ID"].ToString());
}
}
}
Delete selected nodes and their children nodes, and delete corresponding records in the database at the same time
The database table structure is: ID Type Name Parent ID
private void delete ToolStripButton_Click(object sender, EventArgs e)
{
if (Product Category != null)
{
DataRow[] rowChildren = superCargoDataSet1.Product Category.Select("ID=" +Product Category());
if (rowChildren != null)
{
foreach (DataRow row in rowChildren)
{
delete node(row["ID"].ToString());
();
}
}
Product category ();
}
}
private void delete node(string id)
{
DataRow[] rowChildren = superCargoDataSet1.Product Category.Select("parent ID=" + id);
if (rowChildren != null)
{
foreach (DataRow row in rowChildren)
{
delete node(row["ID"].ToString());
();
}
}
}
Right-click TreeView to select
Private void treeView left_MouseDown( object sender, MouseEventArgs e)
{
if( == )
{
TreeNode node = treeView left.GetNodeAt ( , );
if( node != null )//Right-click the node not selected, and the currently selected node does not change. VS2005 is the case.
{
left.SelectedNode = node;
}
}
}
Add top-level nodes: ("Key", "Text")
Add nodes of the same level: ("Key", "Text")
Add child nodes: ("Key", "Text")
Expand all: ()
Collapse all: ()
Reset TreeView
The database table structure is: ID Type Name Parent ID
Copy the codeThe code is as follows:
private void loadTreeView()
{
this.Product Category (superCargoDataSet1.Product Category);
DataTable table = superCargoDataSet1. Product category;
DataRow[] row = ("Parent ID=0");
foreach (DataRow r in row)
{
TreeNode node = Product category (r["ID"].ToString(), r["type name"].ToString());
recursionShow(node, r["ID"].ToString());
}
}
private void recursionShow(TreeNode nodes, string id)
{
DataTable table = superCargoDataSet1. Product category;
DataRow[] row = ("parent ID=" + id);
if (row != null)
{
foreach (DataRow r in row)
{
TreeNode node = (r["ID"].ToString(), r["type name"].ToString());
recursionShow(node, r["ID"].ToString());
}
}
}
Delete selected nodes and their children nodes, and delete corresponding records in the database at the same time
The database table structure is: ID Type Name Parent ID
Copy the codeThe code is as follows:
private void delete ToolStripButton_Click(object sender, EventArgs e)
{
if (Product Category != null)
{
DataRow[] rowChildren = superCargoDataSet1.Product Category.Select("ID=" +Product Category());
if (rowChildren != null)
{
foreach (DataRow row in rowChildren)
{
delete node(row["ID"].ToString());
();
}
}
Product category ();
}
}
private void delete node(string id)
{
DataRow[] rowChildren = superCargoDataSet1.Product Category.Select("parent ID=" + id);
if (rowChildren != null)
{
foreach (DataRow row in rowChildren)
{
delete node(row["ID"].ToString());
();
}
}
}
Right-click TreeView to select
Copy the codeThe code is as follows:
Private void treeView left_MouseDown( object sender, MouseEventArgs e)
{
if( == )
{
TreeNode node = treeView left.GetNodeAt ( , );
if( node != null )//Right-click the node not selected, and the currently selected node does not change. VS2005 is the case.
{
left.SelectedNode = node;
}
}
}