C锐网中的Treeview [英] Treeview in C sharp net

查看:64
本文介绍了C锐网中的Treeview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我正在通过从msaccess检索数据来设计VS Webform中的树形视图.但无法做到.

我有一张三列的桌子

ID名称ManagerID
1 A 0
2 B 1
3 C 1
4 D 2
5 E 3

首先创建一个具有managerid 0的父节点.后来搜索所有具有managerid 1的名称(B和C),并且能够将其添加到父节点A.

但是,当尝试搜索名称为"B"的节点时
treeView1.Nodes.Find(srtext,true)

没有检索到节点.

请帮忙.

Hi All,

I am designing a treeview in VS Webform by retrieving data from msaccess. But unable to do it.

I am having a table with three columns

Id Name ManagerID
1 A 0
2 B 1
3 C 1
4 D 2
5 E 3

First created parent node with managerid 0. Later searched for all names having managerid 1 (B and C) and was able to added to parent node A.

But when tried to search node with Name "B"
treeView1.Nodes.Find(srtext,true)

No nodes are retrieved.

Please help in this.

for (int i = 0; i < intDepth; i++) 
{ 
   query = @"SELECT ID,EMPNAME,MANAGERID FROM EMPLOYEE where ManagerId = " + i.ToString(); 
   myCommand = new OleDbCommand(query, myConnection); 
   OleDbDataReader reader = myCommand.ExecuteReader(); 
   if (i == 0) 
   {
     while (reader.Read()) 
     { 
       parentNode = new TreeNode(reader["EMPNAME"].ToString()); 
       parentNode.Tag = reader["ID"]; 
     } 
     treeView1.Nodes.Add(parentNode); 
   } 
   else 
   { 
     query = @"SELECT ID,EMPNAME,MANAGERID FROM EMPLOYEE where ID = " + i.ToString(); 
     myCommand = new OleDbCommand(query, myConnection); 
     OleDbDataReader reader1 = myCommand.ExecuteReader(); 
     while (reader1.Read() && i != 1) 
     { 
       parentNode = find(reader1["EMPNAME"].ToString()); 
     } 
     while (reader.Read()) 
     { 
       parentNode.Nodes.Add(reader["EMPNAME"].ToString()); 
     } 
}




在此先感谢

Govardhan




Thanks in advance

Govardhan

推荐答案

Nodes.Find搜索节点密钥,而不是节点文本.因此,添加节点时,请确保还指定其键,如下所示:
Nodes.Find searches for the node key and not the node text. Therefore, when you add a node, be sure to specify its key also, like this:
Nodes.Add("B", "B");


然后Nodes.Find将为您搜索该节点.


And then Nodes.Find will search the node for you.


这篇关于C锐网中的Treeview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆