现在的位置: 首页 > 综合 > 正文

Devexpress TreeList 绑定 方式 速度 优化

2013年01月12日 ⁄ 综合 ⁄ 共 1149字 ⁄ 字号 评论关闭

 

首先考虑代码中的字符串比较是否使用到 "==" 符号,该符号在string的比较中非常耗性能,如果存在则需要全部修改成 "Equal()"

按照如上修改后一般速度有显著飞跃,如果还是很卡,参照如下方法:

Devexrepss Treelist 常用绑定方式有两种

1.直接treeList.DataSource=dt;

2.使用AppendNode逐条添加

优缺点:

1.绑定方便,但是速度很慢,特别表现在最大化最小化和关闭的时候,巨卡无比

2.绑定复杂,但是速度很快,推荐使用

下面贴出速度较快的第二种参考代码:

            TreeListNode parentNode = null;
            TreeListNode childNode = null;

            treeList.BeginUnboundLoad();
            treeList.ClearNodes();

            DataView treeDv = dt_F_表二费用表.DefaultView;
            DataTable parentDt = null;
            DataTable childDt = null;
            parentDt = treeDv.ToTable();
            foreach (DataRow parentDr in parentDt.Rows)
            {
                parentNode = this.treeList.AppendNode(new object[] { parentDr["IID"], parentDr["上级费用ID"] }, 0);

                treeDv = new DataView(dt_F_表二费用表);
                treeDv.RowFilter = "上级费用ID='" + parentDr["IID"].ToString() + "'";
                childDt = treeDv.ToTable();
                foreach (DataRow childDr in childDt.Rows)
                {
                    childNode = this.treeList.AppendNode(new object[] { childDr["IID"], childDr["上级费用ID"] }, parentNode);
                }
            }

            treeList.EndUnboundLoad();
            treeList.ExpandAll();

抱歉!评论已关闭.