linux社区爱心援助Linux认证系列教程业界动态站务新闻公司招聘网络学院网址大全LPI专题CISCO专题
设为首页
加入收藏
管理团队
JSP  
JAVA  
PERL  
 您的位置:首页 > 开发语言 > c/c++/c# >
栏目导栏
  php
  JSP
  ASP
  asp.net
  JAVA
  c/c++/c#
  perl
  JavaScript
  Basic
  Delphi
资料搜索
热门文章
·Windows/Linux下配置Eclipse+C
·c语言static与extern的用法
·VC++(Ctime日期函数)应用
·typedef struct和struct的区别
·C/C++对文件操作
·C常用算法程序实例-线性代数方
·C#发送Email邮件方法总结
·struct的初始化,拷贝及指针成
·C语言入门实例 switch使用
·c++二叉树实现源代码
·对初学者的建议:如何学习C语言
·C++ Builder 处理控件中的文本
·常用的BCB & Delphi 函数
·C++入门经典教程完全版01-引言
·C++ Builder 使用Canvas对象的
最新文章
·使用C/C++扩展Python
·C语言入门实例 switch使用
·在C#里实现DATAGRID的打印预览
·如何使用 Visual C# .NET 创建
·C#发送Email邮件方法总结
·一道C#面试题目引发的思考
·c语言艺术清屏
·c语言static与extern的用法
·大数的阶乘算法
·C#编码好习惯
·构造函数,复制构造函数
·typedef struct和struct的区别
·struct的初始化,拷贝及指针成
·超强的指针学习笔记推荐
·STL中erase方法对链表类容器的
Google
 
用TreeView构建树型目录(C#版)
[ 作者:  加入时间:2007-10-26 12:45:01  来自:Linux联盟收集整理 ]
 引言: qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
    参与了一个大型社区程序的开发,现在将相关开发经验陆续总结出来,和大家探讨一下。本节内容主要主要讨论的是用TreeView生成无限级分类的树型目录的问题,相关代码摘录自社区程序中的一个文章发布管理系统中的目录管理部分。 qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
  一、数据库设计 qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
  BBS_BestArticleFolder 精华区目录表 qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
  Key: FolderID qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
  Field name qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   Type qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   Length qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   Default qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   Description qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
  FolderID qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   int qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   4 qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   ID(自动编号) qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
  ParentFolderID qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   int qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   4 qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   0 qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   父目录ID qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
  FolderName qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   Nvarchar qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   80 qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
     qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   目录名 qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
  BoardID qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   int qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   4 qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   0 qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   版块ID qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
  CreaterUserID qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   int qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   4 qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   0 qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   创建者ID qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
  AddTime qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   DateTime qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   8 qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   GetDate() qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   创建时间 qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
  二、树型目录构建过程 qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
  1、安装TreeView控件,我想大多数人都是会安装的,不会安装的去找相关文章一下下。 qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
  2、具体实现: qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
  a 数据生成 qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   #region 树的数据生成事件  qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   private DataView CreateDateView(int boardID) qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   { qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   BBSBestArticleFolderCollection bafc=new BBSBestArticleFolderCollection(); qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   bafc.GetInfoByParentFolderID(boardID,-1); qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   int bafcCount=bafc.Count; qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   DataTable dt = new DataTable("table"); qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   dt.Columns.Add("FolderID",System.Type.GetType("System.String")); qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   dt.Columns.Add("FolderName",System.Type.GetType("System.String")); qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   dt.Columns.Add("ParentFolderID",System.Type.GetType("System.String")); qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   for(int i=0;i qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   { qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   DataRow dr=dt.NewRow(); qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   dr[0]=bafc[i].ID; qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   dr[1]=bafc[i].FolderName; qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   dr[2]=bafc[i].ParentFolderID; qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   dt.Rows.Add(dr); qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   } qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   dv=dt.DefaultView; qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   return dv; qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   } qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   #endregion qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
  一点说明:BBSBestArticleFolderCollection对象是个集合类,里面存储了所有符合条件的数据集合,GetInfoByParentFolderID是其中的一个方法,根据一定条件填充集合类的,此文主要讲TreeView构建树型目录,此处会在另外的文章中详述。 qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
  b qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   #region TreeView节点生成方法 qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   private void CreateTree(TreeNodeCollection folderTreeNodeCollection ,int parentID) qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   { qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   dv.RowFilter= "ParentFolderID="+parentID; qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   int tmpParentFolderID=0; qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   foreach(DataRowView drv in dv) qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   { qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   TreeNode tn=new TreeNode(); qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   tn.ID=drv.Row["FolderID"].ToString(); qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   tn.Text=drv.Row["FolderName"].ToString().Trim(); qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   tmpParentFolderID=Int32.Parse(drv.Row["ParentFolderID"].ToString().Trim()); qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   //tn.CheckBox=true; qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   folderTreeNodeCollection.Add(tn); qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   CreateTree(folderTreeNodeCollection[folderTreeNodeCollection.Count - 1].Nodes,Int32.Parse(tn.ID)); qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   } qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   } qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
  一点解释:递归构建树的各级节点,其中的dv就是上一个方法生成的DataView qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
  c 取得数据的方法有了,生节节点的方法也有了,那么剩下的就是调用了 qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   CreateTree(TreeView1.Nodes,0); qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
   qwBLinux联盟
  一点解释:TreeView1是控件ID,这个大家都知道吧,这里的0其实就是表示顶级目录,从顶级目录递归调用下去DI。 qwBLinux联盟
Linux联盟收集整理 ,转贴请标明原始链接,如有任何疑问欢迎来本站Linux论坛讨论
评论】【加入收藏夹】【 】【打印】【关闭
※ 相关链接
无相关信息