Devexpress TreeList

[一篮饭特稀原创,转载请注明出处http://www.cnblogs.com/wanghafan/archive/2012/02/09/2344253.html]

--Devexpress TreeList 判断空

View Code
 1 repositoryItemTextEdit_费用名称是TreeList的某一列:
2
3 /// 验证不为空_WHF_111201
4
5 /// </summary>
6
7 /// <param name="sender"></param>
8
9 /// <param name="e"></param>
10
11 private void repositoryItemTextEdit_费用名称_Validating(object sender, CancelEventArgs e)
12
13 {
14
15 if (sender != null)
16
17 {
18
19 DevExpress.XtraEditors.TextEdit txt = sender as DevExpress.XtraEditors.TextEdit;
20
21 if (txt != null)
22
23 {
24
25 if (string.IsNullOrEmpty(txt.Text))
26
27 e.Cancel = true;
28
29 }
30
31 }
32
33 }

--Devexpress TreeList 绑定 方式 速度 优化 

View Code
 1 首先考虑代码中的字符串比较是否使用到 "==" 符号,该符号在string的比较中非常耗性能,如果存在则需要全部修改成 "Equal()"
2
3 按照如上修改后一般速度有显著飞跃,如果还是很卡,参照如下方法:
4
5 Devexrepss Treelist 常用绑定方式有两种:
6
7 1.直接treeList.DataSource=dt;
8
9 2.使用AppendNode逐条添加
10
11 优缺点:
12
13 1.绑定方便,但是速度很慢,特别表现在最大化最小化和关闭的时候,巨卡无比
14
15 2.绑定复杂,但是速度很快,推荐使用
16
17 下面贴出速度较快的第二种参考代码:
18
19 TreeListNode parentNode = null;
20 TreeListNode childNode = null;
21
22 treeList.BeginUnboundLoad();
23 treeList.ClearNodes();
24
25 DataView treeDv = dt_F_表二费用表.DefaultView;
26 DataTable parentDt = null;
27 DataTable childDt = null;
28 parentDt = treeDv.ToTable();
29 foreach (DataRow parentDr in parentDt.Rows)
30 {
31 parentNode = this.treeList.AppendNode(new object[] { parentDr["IID"], parentDr["上级费用ID"] }, 0);
32
33 treeDv = new DataView(dt_F_表二费用表);
34 treeDv.RowFilter = "上级费用ID='" + parentDr["IID"].ToString() + "'";
35 childDt = treeDv.ToTable();
36 foreach (DataRow childDr in childDt.Rows)
37 {
38 childNode = this.treeList.AppendNode(new object[] { childDr["IID"], childDr["上级费用ID"] }, parentNode);
39 }
40 }
41
42 treeList.EndUnboundLoad();
43 treeList.ExpandAll();

--Devexpress TreeList 删除 

View Code
 1  treeList_Project是TreeList,无论点击3级节点的某个节点,都可以把根节点一起删除
2
3 private void btn_RemoveProject_Click(object sender, EventArgs e)
4 {
5 if (treeList_Project.FocusedNode == null)
6 return;
7 TreeListNode keyNode=null;
8 switch (treeList_Project.FocusedNode.Level)
9 {
10 case 0:
11 keyNode = treeList_Project.FocusedNode;
12 break;
13 case 1:
14 keyNode = treeList_Project.FocusedNode.ParentNode;
15 break;
16 case 2:
17 keyNode = treeList_Project.FocusedNode.ParentNode.ParentNode;
18 break;
19 }
20 treeList_Project.Nodes.Remove(keyNode);
21 }

--Devexpress TreeList 绑定后 锁定 绑定前 行

View Code
1  int currFocusedRow = treeList_left.GetNodeIndex(treeList_left.FocusedNode);
2
3 //--绑定Binding刷新treeList
4
5 treeList_left.FocusedNode = treeList_left.GetNodeByVisibleIndex(currFocusedRow);

--Devexpress TreeList Check一二级可编辑其他级不可编辑

View Code
 1 代码界面:
 2 private void treeList_CustomNodeCellEdit(object sender, DevExpress.XtraTreeList.GetCustomNodeCellEditEventArgs e)
 3           {
 4               if (e.Node.Level == 0 || e.Node.Level == 1 || e.Node.Level == 2)
 5               {
 6                   if (e.Column.FieldName == "ItGet")
 7                   {
 8                       e.RepositoryItem = repositoryItemCheckEdit_ItGet_0;                    
 9                   }
10                   else
11                   {
12                       e.RepositoryItem = repositoryItemTextEdit_ReadOnly;
13                   }
14               }
15               else
16               {
17                   if (e.Column.FieldName == "ItGet")
18                   {
19                       e.RepositoryItem = repositoryItemCheckEdit_ItGet_1;                    
20                   }
21               }
22          }
23   
24 设计页面:
25 
26   this.repositoryItemCheckEdit_ItGet_1.CheckStyle = DevExpress.XtraEditors.Controls.CheckStyles.Standard;
27   
28   this.repositoryItemCheckEdit_ItGet_0.CheckStyle = DevExpress.XtraEditors.Controls.CheckStyles.UserDefined;
29   this.repositoryItemCheckEdit_ItGet_0.ReadOnly = true;
30   this.repositoryItemCheckEdit_ItGet_0.AllowFocused = false;

 

 

 

 

 

 

posted @ 2012-02-09 17:22  一篮饭特稀  阅读(1768)  评论(0编辑  收藏  举报