C#treeviewツリーメニュー
17304 ワード
///
///TrreView
///
/// datatable
private void InitModuleTree(DataTable dt)
{
// treeview
this.TRole.Nodes.Clear();
int[] father_node= new int[dt.Rows.Count];
int[] child_node= new int[dt.Rows.Count];
string account = Convert.ToString(user_Info.account);
DataTable dtqx = slmenubll.GetData("*", "Library.dbo.czy_role_authority", "where account='" + account + "'");
for (int i = 0; i < father_node.Length; i++)
{
//
string node= dt.Rows[i][2].ToString();
//
int child= int.Parse(dt.Rows[i][2].ToString());
for (int j = 0; j < dtqx.Rows.Count; j++)//
{
int it = int.Parse(dtqx.Rows[j][1].ToString());
if (child== it)
{
if (node.Length > 1) // eg:1-2
{
// 【-】
father_node[i] = int.Parse(node.Substring(0, node.IndexOf('-')));
child_node[i] = int.Parse(node.Substring(node.IndexOf('-') + 1));
}
else
{
//
child_node[i] = int.Parse(node);
TreeNode nodeParent = new TreeNode();
nodeParent.Tag = (child_node[i]).ToString();
nodeParent.Text = dt.Rows[i][0].ToString();
TRole.Nodes.Add(nodeParent);
}
break;
}
}
}
bindChildNote(dt, father_node, child_node);
}
///
///
///
///
///
///
private void bindChildNote(DataTable dt, int[] father_node, int[] child_node)
{
for (int i = 0; i < father_node.Length; i++)
{
if (father_node[i] != 0 && child_node[i] != 0) // ,
{
TreeNode childNode = new TreeNode();
foreach (TreeNode item in tree_Role.Nodes) // treeview
{
//
if (item.Tag.ToString() == father_node[i].ToString())
{
childNode.Tag = child_node[i].ToString();
childNode.Text = dt.Rows[i][0].ToString();
item.Nodes.Add(childNode);
}
}
}
}
//
TRole.ExpandAll();
}