treeView绑定后怎么才能遍历出所有父节点下的所有子节点?
voidTreeViewClassBind()//创建父节点{DataTabletable=newSQLBLL().SelectFristClass();if(table...
void TreeViewClassBind()//创建父节点
{
DataTable table = new SQLBLL().SelectFristClass();
if (table.Rows.Count != 0)
{
for (int i = 0; i < table.Rows.Count; i++)
{
TreeNode tn = new TreeNode();
tn.Text = table.Rows[i]["firstName"].ToString();
tn.Value = table.Rows[i]["id"].ToString();
TreeViewClass.Nodes.Add(tn);
ChildNode(tn, tn.Value);
}
}
}
public void ChildNode(TreeNode node, string fid) //递归取出父节点下的子节点
{
DataTable table = new SQLBLL().SelectSecondClass(int.Parse(fid));
if (table.Rows.Count != 0)
{
for (int i = 0; i < table.Rows.Count; i++)
{
TreeNode tn = new TreeNode();
tn.Text = table.Rows[i]["secondName"].ToString();
tn.Value = table.Rows[i]["id"].ToString();
node.ChildNodes.Add(tn);
// UserNode(tn, tn.Value); //在子节点下创建人员节点
// ChildNode(tn, tn.Value);
}
}
}
绑定后怎么才能遍历出所有父节点下的所有子节点?
急.... 展开
{
DataTable table = new SQLBLL().SelectFristClass();
if (table.Rows.Count != 0)
{
for (int i = 0; i < table.Rows.Count; i++)
{
TreeNode tn = new TreeNode();
tn.Text = table.Rows[i]["firstName"].ToString();
tn.Value = table.Rows[i]["id"].ToString();
TreeViewClass.Nodes.Add(tn);
ChildNode(tn, tn.Value);
}
}
}
public void ChildNode(TreeNode node, string fid) //递归取出父节点下的子节点
{
DataTable table = new SQLBLL().SelectSecondClass(int.Parse(fid));
if (table.Rows.Count != 0)
{
for (int i = 0; i < table.Rows.Count; i++)
{
TreeNode tn = new TreeNode();
tn.Text = table.Rows[i]["secondName"].ToString();
tn.Value = table.Rows[i]["id"].ToString();
node.ChildNodes.Add(tn);
// UserNode(tn, tn.Value); //在子节点下创建人员节点
// ChildNode(tn, tn.Value);
}
}
}
绑定后怎么才能遍历出所有父节点下的所有子节点?
急.... 展开
1个回答
展开全部
// 查找人员
private void button4_Click(object sender, EventArgs e)
{
string username = this.textBox1.Text.ToString().Trim();
if (username == "")
return;
TreeNodeCollection tc = treeView1.Nodes;
this.treeView1.CollapseAll();
FindUser(tc, username);
}
private void FindUser(TreeNodeCollection tc,string username)
{
foreach (TreeNode Node in tc)
{
if (Node.Text.IndexOf(username) >= 0)
{
this.treeView1.SelectedNode = Node;
Node.ForeColor = Color.Orange;
}
FindUser(Node.Nodes, username);
}
}
一个遍历Treeview节点查找节点名字的例子,
其实就是递归循环所有节点
希望对你有用。如果还有问题可以发消息
private void button4_Click(object sender, EventArgs e)
{
string username = this.textBox1.Text.ToString().Trim();
if (username == "")
return;
TreeNodeCollection tc = treeView1.Nodes;
this.treeView1.CollapseAll();
FindUser(tc, username);
}
private void FindUser(TreeNodeCollection tc,string username)
{
foreach (TreeNode Node in tc)
{
if (Node.Text.IndexOf(username) >= 0)
{
this.treeView1.SelectedNode = Node;
Node.ForeColor = Color.Orange;
}
FindUser(Node.Nodes, username);
}
}
一个遍历Treeview节点查找节点名字的例子,
其实就是递归循环所有节点
希望对你有用。如果还有问题可以发消息
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询