一佳一

记录像1+1一样简洁的代码

导航

2010工作代码总结之2(TreeList树形控件)

Posted on 2011-01-31 11:10  一佳一  阅读(381)  评论(0编辑  收藏  举报

1.1字段设置:

 

1.1字段设定

  (1)Run Designer

  (2)点击 Colums

  (3)点击Add添加列,需设置Name(字段名),FiledName(绑定名),Caption(显示名)

1.2代码实现:

(1)初始化树

this.StructureTreeDataSource = BTProduct.Select(p=>p.FState==1 && p.KParentId==null).ToList();

foreach(TreeListNode NOde in StructreTreeNodes)

{

int sid = Convert.ToInt32(node.GetValue(StructreTree.Columns[2]));

node.HasChildren = BTProduct.Select (p=>p.KarentId==sid && p.Fstae ==1).cout()>0?true:false

}

(2)树展开事.触发BeforeExpand事件

private void StructureTree_BeforeExpand(object sender.DevExpress.XtraTreeList.BeforeExpandEventArgs e)

{

if(e.Node.NOdes.Cont==0)

{

int sid = Convert.ToInt32(e.Node.GetValue(StructureTree.Columns[2]));

List<Tproduct> list = BTproduct.Select(p=>p.KParentId==sid && p.Fstate==1).ToList();

foreach(Tproduct sr in list)

{

TreeListNode tl = StructureTree.AppenNode(null,e.Node)

tl.Setvalue(StructreTree.Columns[0],sr.FProductId&& p.Fstate==1)

.count()>0 ? true:false}

}

}

}

(3)获取树某个点的数据

ProductId = Convert.ToInt64(StructureTree.FousedNode.GetValue(ID))