谢谢大家帮助,我做的原代码如下,应该经典吧
//-------------------------------------------------------------------------
//PgMenu_Load载入,项目载入节点
//-------------------------------------------------------------------------
private void PgMenu_Load(object sender, EventArgs e)
{
DataRow myRow;
// TODO: 这行代码将数据加载到表“dS_Load.sy010m”中。您可以根据需要移动或移除它。
this.sy010mTableAdapter.Fill(this.dS_Load.sy010m);
for (int i =0; i< dS_Load.Tables["sy010m"].Rows.Count;i++)
{
myRow
=
dS_Load.Tables["sy010m"].Rows[i];
string ls_module
= myRow[0].ToString().Trim();
string ls_module_f
= myRow[0].ToString().Trim().Substring(0, 4);
string ls_module_l ;
string ls_module_t;
string ls_nm_cha
= myRow[3].ToString().Trim();
if (ls_module.Substring(4, 4) == "0000")
{
TreeNode
tn_1= new TreeNode();
tn_1.Name = ls_module;
tn_1.Text = ls_nm_cha;
treeView1.Nodes.Add(tn_1);
}
//if
else
{
for (int j = 0; j < treeView1.Nodes.Count;j++ )
{
//MessageBox.Show(treeView1.Nodes[j].Name.ToString());
ls_module_t = treeView1.Nodes[j].Name.ToString().Substring(0, 4);
ls_module_l = treeView1.Nodes[j].Name.ToString().Substring(4, 4);
if (ls_module_f == ls_module_t && ls_module_l == "0000")
{
TreeNode tn_2 = new TreeNode();
tn_2.Name = ls_module;
tn_2.Text = ls_nm_cha;
treeView1.Nodes[j].Nodes.Add(tn_2);
}
}
//for
}
//else
}
//for
}
//-------------------------------------------------------------------------
//查询节点下的程序目录
//-------------------------------------------------------------------------
private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
{
string ls_name;
ls_name = treeView1.SelectedNode.Name;
this.sy020mTableAdapter.Fill(this.dS_Load.sy020m,ls_name);
}