search
HomeDatabaseMysql TutorialXtraTreeList使用扎记(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  55                {
 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 141                        //可能存在只取一部分数据的情况,在这种情况下,取控件内ID与表内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中的父子节点的列名。


Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Explain the InnoDB Buffer Pool and its importance for performance.Explain the InnoDB Buffer Pool and its importance for performance.Apr 19, 2025 am 12:24 AM

InnoDBBufferPool reduces disk I/O by caching data and indexing pages, improving database performance. Its working principle includes: 1. Data reading: Read data from BufferPool; 2. Data writing: After modifying the data, write to BufferPool and refresh it to disk regularly; 3. Cache management: Use the LRU algorithm to manage cache pages; 4. Reading mechanism: Load adjacent data pages in advance. By sizing the BufferPool and using multiple instances, database performance can be optimized.

MySQL vs. Other Programming Languages: A ComparisonMySQL vs. Other Programming Languages: A ComparisonApr 19, 2025 am 12:22 AM

Compared with other programming languages, MySQL is mainly used to store and manage data, while other languages ​​such as Python, Java, and C are used for logical processing and application development. MySQL is known for its high performance, scalability and cross-platform support, suitable for data management needs, while other languages ​​have advantages in their respective fields such as data analytics, enterprise applications, and system programming.

Learning MySQL: A Step-by-Step Guide for New UsersLearning MySQL: A Step-by-Step Guide for New UsersApr 19, 2025 am 12:19 AM

MySQL is worth learning because it is a powerful open source database management system suitable for data storage, management and analysis. 1) MySQL is a relational database that uses SQL to operate data and is suitable for structured data management. 2) The SQL language is the key to interacting with MySQL and supports CRUD operations. 3) The working principle of MySQL includes client/server architecture, storage engine and query optimizer. 4) Basic usage includes creating databases and tables, and advanced usage involves joining tables using JOIN. 5) Common errors include syntax errors and permission issues, and debugging skills include checking syntax and using EXPLAIN commands. 6) Performance optimization involves the use of indexes, optimization of SQL statements and regular maintenance of databases.

MySQL: Essential Skills for Beginners to MasterMySQL: Essential Skills for Beginners to MasterApr 18, 2025 am 12:24 AM

MySQL is suitable for beginners to learn database skills. 1. Install MySQL server and client tools. 2. Understand basic SQL queries, such as SELECT. 3. Master data operations: create tables, insert, update, and delete data. 4. Learn advanced skills: subquery and window functions. 5. Debugging and optimization: Check syntax, use indexes, avoid SELECT*, and use LIMIT.

MySQL: Structured Data and Relational DatabasesMySQL: Structured Data and Relational DatabasesApr 18, 2025 am 12:22 AM

MySQL efficiently manages structured data through table structure and SQL query, and implements inter-table relationships through foreign keys. 1. Define the data format and type when creating a table. 2. Use foreign keys to establish relationships between tables. 3. Improve performance through indexing and query optimization. 4. Regularly backup and monitor databases to ensure data security and performance optimization.

MySQL: Key Features and Capabilities ExplainedMySQL: Key Features and Capabilities ExplainedApr 18, 2025 am 12:17 AM

MySQL is an open source relational database management system that is widely used in Web development. Its key features include: 1. Supports multiple storage engines, such as InnoDB and MyISAM, suitable for different scenarios; 2. Provides master-slave replication functions to facilitate load balancing and data backup; 3. Improve query efficiency through query optimization and index use.

The Purpose of SQL: Interacting with MySQL DatabasesThe Purpose of SQL: Interacting with MySQL DatabasesApr 18, 2025 am 12:12 AM

SQL is used to interact with MySQL database to realize data addition, deletion, modification, inspection and database design. 1) SQL performs data operations through SELECT, INSERT, UPDATE, DELETE statements; 2) Use CREATE, ALTER, DROP statements for database design and management; 3) Complex queries and data analysis are implemented through SQL to improve business decision-making efficiency.

MySQL for Beginners: Getting Started with Database ManagementMySQL for Beginners: Getting Started with Database ManagementApr 18, 2025 am 12:10 AM

The basic operations of MySQL include creating databases, tables, and using SQL to perform CRUD operations on data. 1. Create a database: CREATEDATABASEmy_first_db; 2. Create a table: CREATETABLEbooks(idINTAUTO_INCREMENTPRIMARYKEY, titleVARCHAR(100)NOTNULL, authorVARCHAR(100)NOTNULL, published_yearINT); 3. Insert data: INSERTINTObooks(title, author, published_year)VA

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool