DevExpress控件虚拟树VirtualTreeListData使用

关于“DevExpress.XtraTreeList.v10.2” 的树控件treelist和虚拟树IVirtualTreeListData运行速度的比较:

首先编写继承虚拟树接口IVirtualTreeListData的类,MyData如下:

 

namespace test_virtualTreeListAsZMX
{
    //我的数据
    public class MyData:TreeList.IVirtualTreeListData
    {
        protected MyData parentCore;
        protected ArrayList chrildrenCore = new ArrayList();
        protected object[] cellsCore;
        public MyData(MyData parentCoreIn,object[] cellsCoreIn)
        {
            parentCore = parentCoreIn;
            cellsCore = cellsCoreIn;
            if (this.parentCore != null)
            {
                this.parentCore.chrildrenCore.Add(this);
            }
        }

        public void VirtualTreeGetCellValue(VirtualTreeGetCellValueInfo info)
        {
            info.CellData = this.cellsCore[info.Column.AbsoluteIndex];
        }
        public void VirtualTreeGetChildNodes(VirtualTreeGetChildNodesInfo info)
        {
            info.Children = this.chrildrenCore;
        }
        public void VirtualTreeSetCellValue(VirtualTreeSetCellValueInfo info)
        {
            cellsCore[info.Column.AbsoluteIndex] = info.NewCellData;
        }
    }
}

 

其次编写main函数:

namespace test_virtualTreeListAsZMX
{
    public partial class Form1 : Form
    {
        Stopwatch sw = new Stopwatch();
        private int intMax=0;
        public Form1()
        {
            InitializeComponent();
            Initdata();
        }
        private void Initdata()
        {
            int maxNum=1000000;
            MyData dataResource = new MyData(null,null);
            MyData root1 = new MyData(dataResource,new string[] {"root1","high"});
            MyData a1 = new MyData(root1,new string[] {"a1","middle"});
            MyData a2=new MyData(a1,new string[] {"a2","low"});
            MyData root2 = new MyData(dataResource, new string[] { "root2", "high" });
            //MyData mydataTest = treelistData(root2);
            TreeListColumn c1 = new TreeListColumn();
            c1.Caption = "name";
            c1.VisibleIndex = 0;
            TreeListColumn c2 = new TreeListColumn();
            c2.Caption = "value";
            c2.VisibleIndex = 1;
            this.treeList1.Columns.AddRange(new  TreeListColumn[] {c1,c2});
            this.treeList1.DataSource=dataResource;

            //测试
            //ordinaryTreeList
            sw.Start();
            TreeListColumn c5 = new TreeListColumn();
            c5.Caption = "name";
            c5.VisibleIndex = 0;
            TreeListColumn c6 = new TreeListColumn();
            c6.Caption = "value";
            c6.VisibleIndex = 1;
            this.ordinaryTreeList.Columns.AddRange(new TreeListColumn[] { c5, c6 });
            TreeListNode root = this.ordinaryTreeList.AppendNode(new string[] { "a1", "low" }, 0);
            root.Expanded = true;
            for (int jj = 0; jj < maxNum; jj++)
            {
                TreeListNode tln2 = ordinaryTreeList.AppendNode(new string[] { "a2", "low" }, root);
            }
            ordinaryTreeList.ExpandAll();
            sw.Stop();
            Console.WriteLine("ordinaryTreeList_open:" + sw.ElapsedMilliseconds);


            //virtualTreeList
            sw.Start();
            TreeListColumn c3 = new TreeListColumn();
            c3.Caption = "name";
            c3.VisibleIndex = 0;
            TreeListColumn c4 = new TreeListColumn();
            c4.Caption = "value";
            c4.VisibleIndex = 1;
            this.virtualTreeList.Columns.AddRange(new TreeListColumn[] { c3, c4 });
            MyData dataResource1 = new MyData(null, null);
            a2 = new MyData(dataResource1, new string[] { "a1", "low" });
            for (int ii = 0; ii < maxNum; ii++)
            {
                MyData a3 = new MyData(a2, new string[] { "a2", "low" });
            }
            this.virtualTreeList.DataSource = dataResource1;
            virtualTreeList.ExpandAll();
            sw.Stop();
            Console.WriteLine("virtualTreeList_open:" + sw.ElapsedMilliseconds);
        }
        private MyData treelistData(MyData myDataIn)
        {
            intMax++;
            MyData imydata1 = new MyData(myDataIn, new string[] { "a2", "low" });
            MyData imydata2=null;
            if (intMax < 10)
            {
                imydata2 = treelistData(imydata1);
                return imydata2;
            }
            else
                return imydata1;
        }
        [STAThread]
        static void Main(string[] args)
        {
            Application.EnableVisualStyles();
            Application.Run(new Form1());
        }
    }
}


运行结果如下:

当节点数为100时,差别不大:

普通树完全展开花费:243 millisecond。

虚拟树完全展开花费:256 millisecond。

 

 

节点数达到1000000个后,差别明显:

普通树完全展开花费:3106 millisecond。

虚拟树完全展开花费:7067 millisecond。

 

截图如下:

 

 

由此可见,虚拟树的好处还有待探索,希望能在其他方面发现它运行速度上的优势。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
================================== ==注意:一共2个压缩包,这是第1个== ================================== *提示:无自动安装程序,包含所有源码、例子、帮助,请按照安装顺序安装!!! New Features in 13.1.4 (VCL Product Line) Breaking Changes To learn about breaking changes in this version, please refer to the following page: Breaking Changes in 13.1.4 (VCL Product Line) Known Issues To learn about known issues in this version, please refer to the following page: Known Issues in 13.1.4 (VCL Product Line) The following sections list all minor and major changes in DevExpress VCL 13.1.4. Note that products, controls and libraries which aren't mentioned in the list below are included in the unified installer for compatibility, but have not been updated. Enhancements and Updates New Features/Updates VCL Subscription ExpressTile Control ExpressDataController Resolved Issues ExpressBars Suite ExpressLayout Control ExpressNavBar ExpressPageControl ExpressPivotGrid Suite ExpressPrinting System ExpressQuantumGrid Suite ExpressQuantumTreeList Suite ExpressScheduler Suite ExpressSkins Library ExpressSpreadSheet ExpressTile Control ExpressVerticalGrid Suite ExpressDataController ExpressEditors Library ExpressLibrary Installation (VCL) New Features/Updates VCL Subscription S170932 - Documentation - Describe that the ExpressLayout Control and ExpressDocking Library are incompatible ExpressTile Control S172299 - Center the Back button and title text vertically within the title Common Libraries ExpressDataController S172107 - Add the capability to disable multi-threaded operations at the level of custom data sources (TcxCustomDataSource descendants) Resolved Issues ExpressBars Suite Q476901 - Documentation - The "Ribbon Application Menu" topic does not contain the menu creation steps that are specific to TdxRibbonBackstageView Q452658 - Documentation - The TdxCustomRibbonGalleryItem.GalleryGroups property is not marked as deprecated and is used in topics instead of TdxCustomRibbonGalleryItem.GalleryCategories Q513198 -
Delphi DevExpress控件Devexpress公司旗下的用户界面套包,包含了数据录入、图表、数据分析、导航、布局等多种控件,可以帮助开发者创建出优秀的用户体验和高影响力的业务解决方案。同时,Delphi DevExpress控件还可以利用开发者现有的VCL技能为未来构建下一代应用程序。\[1\]\[2\] 要在Delphi中使用DevExpress控件,您需要按照以下步骤进行操作: 1. 下载并安装DevExpress VCL Controls套件。 2. 在Delphi中创建一个新项目。 3. 在项目中添加DevExpress控件单元,例如dxShellControls。 4. 在您的代码中使用DevExpress控件的类和方法来实现您的需求。 需要注意的是,如果您在C++Builder项目中使用DevExpress控件,并且禁用了"Disable incremental linker"和"Link with runtime packages"选项,那么在重新构建应用程序时可能会出现错误。\[3\] 希望这些信息对您有所帮助! #### 引用[.reference_title] - *1* *3* [Delphi开发工具DevExpress VCL全新发布v21.1.5](https://blog.csdn.net/AABBbaby/article/details/120409370)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [Delphi开发工具DevExpress VCL 2021年新版首发(附高速下载)](https://blog.csdn.net/AABBbaby/article/details/113307597)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值