Participated in a large-scale community program development, and now the relevant development experience is summed up, and we discuss. This section mainly discusses the problem of generating a tree-type catalog of infinite classes with the TreeView, and the relevant code extracts from an article in the Community program to publish the Directory Management section of the management system.
First, the database design
Bbs_bestarticlefolder Essence Area Catalogue Table
Key:folderid
Field Name
Type
Length
Default
Description
FolderID
Int
4
ID (AutoNumber)
Parentfolderid
Int
4
0
Parent Directory ID
FolderName
Nvarchar
80
Directory Name
Boardid
Int
4
0
Forum ID
Createruserid
Int
4
0
Creator ID
Addtime
Datetime
8
GetDate ()
Creation time
Second, the tree directory construction process
1, install the TreeView control, I think most people will be installed, will not be installed to find related articles under.
Note: Bbsbestarticlefoldercollection object is a collection class, which stores all eligible data sets, Getinfobyparentfolderid is one of the methods, according to certain conditions to populate the collection class, This article is mainly about the TreeView Building Tree directory, which will be detailed in another article.
B
#region TreeView Node Generation method
private void Createtree (treenodecollection foldertreenodecollection, int parentid)
{
Dv. Rowfilter= "parentfolderid=" +parentid;
int tmpparentfolderid=0;
foreach (DataRowView DRV in DV)
{
TreeNode tn=new TreeNode ();
Tn.id=drv. row["FolderID"]. ToString ();
Tn. Text=drv. row["FolderName"]. ToString (). Trim ();
Tmpparentfolderid=int32.parse (DRV. row["Parentfolderid"]. ToString (). Trim ());
One explanation: The recursive construction of tree levels of nodes, where DV is the last method generated DataView
c the method of obtaining data has, the method of the birth point is also have, then the rest is to call the
Createtree (treeview1.nodes,0);
One explanation: TreeView1 is the control ID, as you all know, here's 0 is to represent the top-level directory, recursive call down from the top-level directory di.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.