TreeView绑定数据库出错!急!急急急!!!(C#) 20
1个回答
展开全部
#region[函数] [TreeView递归函数]
#region [函数] [树型2级显示]
public void Fun_Tree(TreeView TREE, SqlConnection Link_Conn)
{
DS = Link.SQL_Select("select * from Basic_Bm", Link_Conn);
DT = DS.Tables[0];
if (Tree_Node_P == false)
{
foreach (DataRow DR in DT.Rows)
{
if (DR.ItemArray[2].ToString() == "0")
{
TreeNode TN = new TreeNode();
TN.Tag = DR.ItemArray[0].ToString();
TN.Text = DR.ItemArray[1].ToString();
TREE.Nodes.Add(TN);
}
}
Tree_Node_P = true;
}
foreach (DataRow DR_2 in DT.Rows)
{
foreach (TreeNode TN_2 in TREE.Nodes)
{
if (DR_2.ItemArray[2].ToString() == TN_2.Text)
{
TreeNode TN_3 = new TreeNode();
TN_3.Tag = DR_2.ItemArray[0].ToString();
TN_3.Text = DR_2.ItemArray[1].ToString();
TN_2.Nodes.Add(TN_3);
Fun_Tree_2(TN_3);
}
}
}
}
#endregion
#region [函数] [树型>3级递归]
public void Fun_Tree_2(TreeNode T_Name)
{
foreach (DataRow DR_2 in DT.Rows)
{
if (DR_2.ItemArray[2].ToString() == T_Name.Text)
{
TreeNode TN_3 = new TreeNode();
TN_3.Tag = DR_2.ItemArray[0].ToString();
TN_3.Text = DR_2.ItemArray[1].ToString();
T_Name.Nodes.Add(TN_3);
Fun_Tree_2(TN_3);
}
}
}
#endregion
#endregion
#region [函数] [树型2级显示]
public void Fun_Tree(TreeView TREE, SqlConnection Link_Conn)
{
DS = Link.SQL_Select("select * from Basic_Bm", Link_Conn);
DT = DS.Tables[0];
if (Tree_Node_P == false)
{
foreach (DataRow DR in DT.Rows)
{
if (DR.ItemArray[2].ToString() == "0")
{
TreeNode TN = new TreeNode();
TN.Tag = DR.ItemArray[0].ToString();
TN.Text = DR.ItemArray[1].ToString();
TREE.Nodes.Add(TN);
}
}
Tree_Node_P = true;
}
foreach (DataRow DR_2 in DT.Rows)
{
foreach (TreeNode TN_2 in TREE.Nodes)
{
if (DR_2.ItemArray[2].ToString() == TN_2.Text)
{
TreeNode TN_3 = new TreeNode();
TN_3.Tag = DR_2.ItemArray[0].ToString();
TN_3.Text = DR_2.ItemArray[1].ToString();
TN_2.Nodes.Add(TN_3);
Fun_Tree_2(TN_3);
}
}
}
}
#endregion
#region [函数] [树型>3级递归]
public void Fun_Tree_2(TreeNode T_Name)
{
foreach (DataRow DR_2 in DT.Rows)
{
if (DR_2.ItemArray[2].ToString() == T_Name.Text)
{
TreeNode TN_3 = new TreeNode();
TN_3.Tag = DR_2.ItemArray[0].ToString();
TN_3.Text = DR_2.ItemArray[1].ToString();
T_Name.Nodes.Add(TN_3);
Fun_Tree_2(TN_3);
}
}
}
#endregion
#endregion
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询