treeview控件的动态怎么生成! 哪位高手指教一下! treeview怎么动态生成,后台用sql server,前台是windows应用程序,c#编写!! treeview 的各个节点的值从数据库读! 求数据库设计和前台代码!! 万分感谢!! 50分回报!! 谢谢!! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 用treeview递归string[] tree=GetSubTask(nTaskID)//取出顶级任务的名称的数组,这里可能不正确, for(int i=0 ;i<count;i++)//count 顶级数量 { TreeNode rootNode = new TreeNode(tree[i]); rootNode.ImageIndex = 2; rootNode.SelectedImageIndex = 0; treeView1.Nodes.AddRange(new System.Windows.Forms.TreeNode[]{rootNode}); treeitem(rootNode,tree[i]) }private void treeitem(TreeNode treeup,int nTaskID){ //查询下级 string[] tree=GetSubTask(nTaskID) for(int i=0 ;i<count;i++) { TreeNode myComputer = new TreeNode(tree[i]); myComputer.ImageIndex = 2; myComputer.SelectedImageIndex = 0; treeup.Nodes.Add(myComputer); treeitem(myComputer,tree[i]); }} 数据库可以设计成ID,cname,up_id1,中国,02,吉林,13,长春,2也可以设计成ID是变长的,例:01,中国0122,吉林012201,长春根据位数判断级别 如果关系不是很复杂,建议使用 zwfhome1(任由风吹)说的第二种方法,这种方法生成树快,填充treeview比第一种快很多。 private void SetSourceClassTolvSource(TreeNode tn) { DataRow[] dr = this.dsSource.Tables["Source"].Select("parent_id=" + ((tn == null) ? "0" : tn.Tag.ToString().Substring(0, tn.Tag.ToString().Length - 1))); foreach (DataRow dr1 in dr) { TreeNode tn1 = new TreeNode(dr1["Source_name"].ToString()); tn1.Tag = dr1["Source_id"].ToString() + dr1["Source_Class"].ToString(); tn1.ImageIndex = (dr1["Source_Class"].ToString() == "0") ? 0 : 2; tn1.SelectedImageIndex = tn1.ImageIndex; if (tn != null) tn.Nodes.Add(tn1); else this.tvSource.Nodes.Add(tn1); this.SetSourceClassTolvSource(tn1); } } 怎么实现:WPF DataGrid控件在鼠标拖动时,选中单元格 Ajax比较弱弱的问题..... 一个小问题,,找个可以解释的理由??? 如何实现对MP3文件进行分割? 简单的问题,高手进来帮忙一下 问个奇怪的Windows应用程序和asp.net应用程序的问题 一个小问题,高手低手都欢迎,解决马上给分 很简单的问题,请各位帮忙! 如何将datagrid中的数据保存到新建的excel文件中?能给完整具体代码吗?谢谢!! 如何解决visul studio.net 和office 2000 的冲突 DataGrid控件中,空的日期字段如何进行区分表达? C#连接数据库的方法
string[] tree=GetSubTask(nTaskID)//取出顶级任务的名称的数组,这里可能不正确,
for(int i=0 ;i<count;i++)//count 顶级数量
{
TreeNode rootNode = new TreeNode(tree[i]);
rootNode.ImageIndex = 2;
rootNode.SelectedImageIndex = 0;
treeView1.Nodes.AddRange(new System.Windows.Forms.TreeNode[]{rootNode});
treeitem(rootNode,tree[i])
}private void treeitem(TreeNode treeup,int nTaskID)
{
//查询下级
string[] tree=GetSubTask(nTaskID)
for(int i=0 ;i<count;i++)
{
TreeNode myComputer = new TreeNode(tree[i]);
myComputer.ImageIndex = 2;
myComputer.SelectedImageIndex = 0;
treeup.Nodes.Add(myComputer);
treeitem(myComputer,tree[i]);
}
}
1,中国,0
2,吉林,1
3,长春,2也可以设计成ID是变长的,例:
01,中国
0122,吉林
012201,长春
根据位数判断级别
{
DataRow[] dr = this.dsSource.Tables["Source"].Select("parent_id=" + ((tn == null) ? "0" : tn.Tag.ToString().Substring(0, tn.Tag.ToString().Length - 1)));
foreach (DataRow dr1 in dr)
{
TreeNode tn1 = new TreeNode(dr1["Source_name"].ToString());
tn1.Tag = dr1["Source_id"].ToString() + dr1["Source_Class"].ToString();
tn1.ImageIndex = (dr1["Source_Class"].ToString() == "0") ? 0 : 2;
tn1.SelectedImageIndex = tn1.ImageIndex;
if (tn != null) tn.Nodes.Add(tn1);
else this.tvSource.Nodes.Add(tn1);
this.SetSourceClassTolvSource(tn1);
}
}