20151124002 TreeView Menu Operation
protected void Filltree ()
{
SqlConnection1 = new System.Data.SqlClient.SqlConnection ();
sqlconnection1.connectionstring = str_connect_88;
String sql_text1 = "SELECT DISTINCT [PER_DPT] from [Kqdata]. [dbo]. [Personal] ";
This. SqlDataAdapter1 = new System.Data.SqlClient.SqlDataAdapter (SQL_TEXT1, SqlConnection1);
This. DataSet1 = new System.Data.DataSet ();
This. Sqlconnection1.open ();
This. SqlDataAdapter1.Fill (DataSet1, "personal");
This. Sqlconnection1.close ();
Int32 int_count = dataset1.tables[0]. Rows.Count;
TreeNode tmp;
TMP = new TreeNode ("xx company");
TREEVIEW1.NODES.ADD (TMP);
Treeview1.selectednode = tmp;
//dgv_from. DataSource = Dataset1.tables[0];
for (int i = 0; i < Int_count; i++)
{
TreeNode tn = new TreeNode ();
TN. Text = Dataset1.tables[0]. rows[i]["PER_DPT"]. ToString ();
TreeView1.SelectedNode.Nodes.Add (TN);
//2
string sql_text2 = "Select Distinct [Per_zhu] from [Kqdata]. [dbo]. [Personal] where [per_dpt] = ' "+ tn. Text + "'";
this. SqlDataAdapter1 = new System.Data.SqlClient.SqlDataAdapter (SQL_TEXT2, SqlConnection1);
This. DataSet2 = new System.Data.DataSet ();
This. Sqlconnection1.open ();
This. SqlDataAdapter1.Fill (DataSet2, "personal");
This. Sqlconnection1.close ();
Treeview1.selectednode = TN;
Int32 Int_count2 = dataset2.tables[0]. Rows.Count;
if (Int_count2 > 0)
{
for (int i2 = 0; i2 < Int_count2; i2++)
{
TreeNode tn2 = new TreeNode ();
Tn2. Text = Dataset2.tables[0]. rows[i2]["Per_zhu"]. ToString ();
if (tn2. Text.trim ()! = "")
{
TREEVIEW1.SELECTEDNODE.NODES.ADD (TN2);
}
Treeview1.selectednode = TN;
//3
string sql_text3 = "SELECT distinct [per_ Ban] from [Kqdata]. [dbo]. [Personal] where [per_zhu] = ' "+ tn2. Text + "'";
this. SqlDataAdapter1 = new System.Data.SqlClient.SqlDataAdapter (SQL_TEXT3, SqlConnection1);
This. DataSet3 = new System.Data.DataSet ();
This. Sqlconnection1.open ();
This. SqlDataAdapter1.Fill (DataSet3, "personal");
This. Sqlconnection1.close ();
Treeview1.selectednode = TN2;
Int32 Int_count3 = dataset3.tables[0]. Rows.Count;
if (Int_count3 > 0)
{
for (int i3 = 0; i3 < Int_count3; i3++)
{
TreeNode tn3 = new TreeNode ();
Tn3. Text = Dataset3.tables[0]. rows[i3]["Per_ban"]. ToString ();
if (tn3. Text.trim ()! = "")
{
TREEVIEW1.SELECTEDNODE.NODES.ADD (TN3);
}
Treeview1.selectednode = TN2;
}
}
Treeview1.selectednode = TN;
}
}
Treeview1.selectednode = tmp;
//
}
Expand all nodes in the component
TreeView1.SelectedNode.ExpandAll ();
Locating the root node
Treeview1.selectednode = Treeview1.nodes[0];
}
private void Frm_main_load (object sender, EventArgs e)
{
filltree ( );
}
private void treeView1_AfterSelect (object sender, TreeViewEventArgs e)
{
if (e.action = = treeviewaction.bymouse)//Determine if the mouse is triggered by the
{
if (treeview1.selectednode! = null)
{
MessageBox.Show (TreeView1.SelectedNode.Text);
}
}
}
20151124002 treeView Menu Actions