XtraTreeList使用扎记(2)
http://www.cnblogs.com/xxm/archive/2006/10/18/532009.html 写完一部分代码。都快要四点了。最近做项目,好久没有往博客上放东西了。趁着还有些精神,赶紧把上次没有发布的代码补上。使用TreeList都有两个月了。发现自己使用它的Tag属性达到了变态的地步,
http://www.cnblogs.com/xxm/archive/2006/10/18/532009.html
写完一部分代码。都快要四点了。最近做项目,好久没有往博客上放东西了。趁着还有些精神,赶紧把上次没有发布的代码补上。使用TreeList都有两个月了。发现自己使用它的Tag属性达到了变态的地步,在Tag属性里放的Struct里面的东西越来越多。在某种程度上。没有这个属性。我的好多工作是无法完成的。考虑到装箱和拆箱的过程,却也无可奈何。这是一个通过DataTable来自动绑定TreeList的类,考虑到了部分数据显示和部分字段显示,在每个SimpleBind的重载中都加入了这一部分的处理,强调一点。我所处理的数据都是以父子节点为基础的绑定。同时。子节点是以1开始。父节点是以
0开始。这样在存入父子节点ID的时候要注意。代码如下,谨供自己和自己一样的菜鸟参考。
1using System.Collections ;
2using System.Data ;
3using BusinessEntity;
4using PersistenceLayer;
5using DevExpress.XtraTreeList ;
6using DevExpress.XtraTreeList.Nodes ;
7using DevExpress.XtraTreeList.Columns ;
8namespace NskProject
9{
10 /**////
11 /// 一些实现或辅助绑定TreeList的静态方法。
12 ///
13 public class BindTreeList
14 {
15 /**////
16 /// 初级绑定方法,给定的表中有父子关系的字字段,默认情况下表内所有字段都被绑定到控件内
17 ///
18 /// 数据源表
19 /// 需要绑定的控件
20 public static void SimpleMode(DataTable Dt,TreeList Ti)
21 {
22 if(ParentFieldName==null && ChildFieldName==null)
23 {
24 return;
25 }
26
27 Ti.ParentFieldName=ParentFieldName;
28 Ti.KeyFieldName=ChildFieldName;
29 Ti.DataSource=Dt;
30 Ti.PopulateColumns();
31 return;
32 }
33 /**////
34 /// 初级绑定方法:在前一方法的基础上增加了将某一字段加入到Tag属性中去。保存附加信息
35 /// 该表在赋值前以父节点为基础进行了排序
36 ///
37 /// 数据源表
38 /// 附加到Tag属性中的字段
39 /// 需要绑定的控件
40 public static void SimpleMode(DataTable Dt,DataColumn TagColumn,TreeList Ti)
41 {
42 if(ParentFieldName==null && ChildFieldName==null)
43 {
44 return;
45 }
46 int TagColumnIndex=Dt.Columns.IndexOf(TagColumn);
47 foreach(DataRow dr in Dt.Rows)
48 {
49 object[] Data=new object[Dt.Columns.Count-3];
50 object Tag=new object() ;
51 Object[]Source=dr.ItemArray;
52 int count=0;
53 //显示数据与附加数据分离
54 for(int i=0;i
56 if(i!=TagColumnIndex &&i!=-1)
57 {
58 Data[count]=Source[count];
59 count++;
60 }
61 else
62 {
63 Tag=Source[i];
64 }
65 }
66 int ParentID=Convert.ToInt32(dr[ParentFieldName]);
67 int ChildID=Convert.ToInt32(dr[ChildFieldName]);
68 int Balance=0;
69 if(ParentID==0)
70 {
71 TreeListNode Node=Ti.AppendNode(Data,null);
72 Node.Tag=Tag;
73 if(Node.Id!=ChildID)
74 {
75 Balance=ChildID;
76 //可能存在只取一部分数据的情况,在这种情况下,取控件内ID与表内ID之间的差额
77 }
78 }
79 else
80 {
81 TreeListNode ParentNode;
82 if(Balance>0)//两种不同情况的取得父节点的方法
83 {
84 ParentNode=Ti.FindNodeByID(ParentID-Balance);
85 }
86 else
87 {
88 ParentNode=Ti.FindNodeByID(ParentID-1);
89 }
90 if(ParentNode!=null)
91 {
92 TreeListNode Node=Ti.AppendNode(Data,ParentNode);
93 Node.Tag=Tag;
94 }
95 }
96 }
97 }
98 /**////
99 /// 针对有时候并不是加载一张表内的所有内容,对此加以变形,对于存在于表中不在列表内的字段
100 /// 给删除,对于不在表内而在列表内的值赋空值加入列表内
101 ///
102 /// 数据源表
103 /// 需要在TreeList中显示的字段列表
104 /// 需要绑定的控件
105 public static void SimpleMode(DataTable Dt,string Fields,TreeList Ti)
106 {
107 Ti.Nodes.Clear();
108 int Balance=0;
109 string[] FieldList=Fields.Split(",".ToCharArray());
110 if(ParentFieldName==null && ChildFieldName==null)
111 {
112 return;
113 }
114 foreach(DataRow dr in Dt.Rows)
115 {
116 int index=0;
117 Object[] Data=new object[FieldList.Length];
118 foreach(string o in FieldList)
119 {
120 if(Dt.Columns.IndexOf(o)>-1)
121 {
122 string n=dr[o].ToString().Trim();
123 Data[index]=n;
124 }
125 else
126 {
127 Data[index]="";
128 }
129 index++;
130 }
131
132 int ParentID=Convert.ToInt32(dr[ParentFieldName]);
133 int ChildID=Convert.ToInt32(dr[ChildFieldName]);
134
135 if(ParentID==0)
136 {
137 TreeListNode Node=Ti.AppendNode(Data,null);
138 if(Node.Id!=ChildID-1)
139 {
140 Balance=Node.Id
142 }
143 }
144 else
145 {
146 TreeListNode ParentNode;
147 if(Balance>0)//两种不同情况的取得父节点的方法
148 {
149 ParentNode=Ti.FindNodeByID(ParentID-Balance);
150 }
151 else
152 {
153 ParentNode=Ti.FindNodeByID(ParentID-1);
154 }
155 if(ParentNode!=null)
156 {
157 TreeListNode Node=Ti.AppendNode(Data,ParentNode);
158
159 }
160 }
161 }
162 }
163 /**////
164 ///
165 ///
166 ///
167 ///
168 ///
169 ///
170 public static void SimpleMode(DataTable Dt,string Fields,TreeList Ti,string TagColumn)
171 {
172 Ti.Nodes.Clear();
173 int Balance=0;
174 string[] FieldList=Fields.Split(",".ToCharArray());
175 if(ParentFieldName==null && ChildFieldName==null)
176 {
177 return;
178 }
179 foreach(DataRow dr in Dt.Rows)
180 {
181 int index=0;
182 Object[] Data=new object[FieldList.Length];
183 foreach(string o in FieldList)
184 {
185 if(o!=TagColumn && Dt.Columns.IndexOf(o)>-1)
186 {
187 string n=dr[o].ToString().Trim();
188 Data[index]=n;
189 }
190 else
191 {
192 Data[index]="";
193 }
194 index++;
195 }
196
197 int ParentID=Convert.ToInt32(dr[ParentFieldName]);
198 int ChildID=Convert.ToInt32(dr[ChildFieldName]);
199
200 if(ParentID==0)
201 {
202 TreeListNode Node=Ti.AppendNode(Data,null);
203 Node.Tag =dr[TagColumn];
204 if(Node.Id!=ChildID)
205 {
206 Balance=ChildID;
207 //可能存在只取一部分数据的情况,在这种情况下,取控件内ID与表内ID之间的差额
208 }
209 }
210 else
211 {
212 TreeListNode ParentNode;
213 if(Balance>0)//两种不同情况的取得父节点的方法
214 {
215 ParentNode=Ti.FindNodeByID(ParentID-Balance);
216 }
217 else
218 {
219 ParentNode=Ti.FindNodeByID(ParentID-1);
220 }
221 if(ParentNode!=null)
222 {
223 TreeListNode Node=Ti.AppendNode(Data,ParentNode);
224 Node.Tag =dr[TagColumn];
225
226 }
227 }
228 }
229 }
230 private static string _ParentFieldName="";
231 private static string _ChildFieldName="";
232 public static string ParentFieldName
233 {
234 get{return _ParentFieldName;}
235 set{_ParentFieldName=value;}
236 }
237
238 public static string ChildFieldName
239 {
240 get{return _ChildFieldName;}
241 set{_ChildFieldName=value;}
242 }
243
244 }
245}
246
这是一个静态方法,在执行SimpleBind方法前。必须对ChildFieldName和ParentFieldName进行赋值,它们对应着Dt中的父子节点的列名。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



CrystalDiskMark is a small HDD benchmark tool for hard drives that quickly measures sequential and random read/write speeds. Next, let the editor introduce CrystalDiskMark to you and how to use crystaldiskmark~ 1. Introduction to CrystalDiskMark CrystalDiskMark is a widely used disk performance testing tool used to evaluate the read and write speed and performance of mechanical hard drives and solid-state drives (SSD). Random I/O performance. It is a free Windows application and provides a user-friendly interface and various test modes to evaluate different aspects of hard drive performance and is widely used in hardware reviews

foobar2000 is a software that can listen to music resources at any time. It brings you all kinds of music with lossless sound quality. The enhanced version of the music player allows you to get a more comprehensive and comfortable music experience. Its design concept is to play the advanced audio on the computer The device is transplanted to mobile phones to provide a more convenient and efficient music playback experience. The interface design is simple, clear and easy to use. It adopts a minimalist design style without too many decorations and cumbersome operations to get started quickly. It also supports a variety of skins and Theme, personalize settings according to your own preferences, and create an exclusive music player that supports the playback of multiple audio formats. It also supports the audio gain function to adjust the volume according to your own hearing conditions to avoid hearing damage caused by excessive volume. Next, let me help you

NetEase Mailbox, as an email address widely used by Chinese netizens, has always won the trust of users with its stable and efficient services. NetEase Mailbox Master is an email software specially created for mobile phone users. It greatly simplifies the process of sending and receiving emails and makes our email processing more convenient. So how to use NetEase Mailbox Master, and what specific functions it has. Below, the editor of this site will give you a detailed introduction, hoping to help you! First, you can search and download the NetEase Mailbox Master app in the mobile app store. Search for "NetEase Mailbox Master" in App Store or Baidu Mobile Assistant, and then follow the prompts to install it. After the download and installation is completed, we open the NetEase email account and log in. The login interface is as shown below

Cloud storage has become an indispensable part of our daily life and work nowadays. As one of the leading cloud storage services in China, Baidu Netdisk has won the favor of a large number of users with its powerful storage functions, efficient transmission speed and convenient operation experience. And whether you want to back up important files, share information, watch videos online, or listen to music, Baidu Cloud Disk can meet your needs. However, many users may not understand the specific use method of Baidu Netdisk app, so this tutorial will introduce in detail how to use Baidu Netdisk app. Users who are still confused can follow this article to learn more. ! How to use Baidu Cloud Network Disk: 1. Installation First, when downloading and installing Baidu Cloud software, please select the custom installation option.

MetaMask (also called Little Fox Wallet in Chinese) is a free and well-received encryption wallet software. Currently, BTCC supports binding to the MetaMask wallet. After binding, you can use the MetaMask wallet to quickly log in, store value, buy coins, etc., and you can also get 20 USDT trial bonus for the first time binding. In the BTCCMetaMask wallet tutorial, we will introduce in detail how to register and use MetaMask, and how to bind and use the Little Fox wallet in BTCC. What is MetaMask wallet? With over 30 million users, MetaMask Little Fox Wallet is one of the most popular cryptocurrency wallets today. It is free to use and can be installed on the network as an extension

After long pressing the play button of the speaker, connect to wifi in the software and you can use it. Tutorial Applicable Model: Xiaomi 12 System: EMUI11.0 Version: Xiaoai Classmate 2.4.21 Analysis 1 First find the play button of the speaker, and press and hold to enter the network distribution mode. 2 Log in to your Xiaomi account in the Xiaoai Speaker software on your phone and click to add a new Xiaoai Speaker. 3. After entering the name and password of the wifi, you can call Xiao Ai to use it. Supplement: What functions does Xiaoai Speaker have? 1 Xiaoai Speaker has system functions, social functions, entertainment functions, knowledge functions, life functions, smart home, and training plans. Summary/Notes: The Xiao Ai App must be installed on your mobile phone in advance for easy connection and use.

Apple rolled out the iOS 17.4 update on Tuesday, bringing a slew of new features and fixes to iPhones. The update includes new emojis, and EU users will also be able to download them from other app stores. In addition, the update also strengthens the control of iPhone security and introduces more "Stolen Device Protection" setting options to provide users with more choices and protection. "iOS17.3 introduces the "Stolen Device Protection" function for the first time, adding extra security to users' sensitive information. When the user is away from home and other familiar places, this function requires the user to enter biometric information for the first time, and after one hour You must enter information again to access and change certain data, such as changing your Apple ID password or turning off stolen device protection.

With the rapid development of network technology, our lives have also been greatly facilitated, one of which is the ability to download and share various resources through the network. In the process of downloading resources, magnet links have become a very common and convenient download method. So, how to use Thunder magnet links? Below, I will give you a detailed introduction. Xunlei is a very popular download tool that supports a variety of download methods, including magnet links. A magnet link can be understood as a download address through which we can obtain relevant information about resources.
