zoukankan      html  css  js  c++  java
  • DevExpress.XtraLayout.LayoutControl 动态添加控件

    // Create an item within a specified group,
    // bound to a specified data field with the specified editor
    private LayoutControlItem CreateItemWithBoundEditor(BaseEdit editor, object dataSource,
       string dataMember, LayoutControlGroup parentGroup) {
       editor.DataBindings.Add("EditValue", dataSource, dataMember);
       LayoutControlItem item = parentGroup.AddItem(dataMember, editor) as LayoutControlItem;
       return item;
    }
    private void CreateLayout() {
       //Add First Name and Last Name items
       LayoutControlItem itemFirstName = CreateItemWithBoundEditor(new TextEdit(), employeesSource,
          "FirstName", layoutControl1.Root);
       LayoutControlItem itemLastName = CreateItemWithBoundEditor(new TextEdit(), employeesSource,
          "LastName", layoutControl1.Root);
       // Move the Last Name to the right of the First Name
       itemLastName.Move(itemFirstName, InsertTypes.Right);

       // Add the Birthday group with a birthday editor inside
       LayoutControlGroup birthdayGroup = layoutControl1.AddGroup("Birthday Information");
       CreateItemWithBoundEditor(new DateEdit(), employeesSource, "BirthDate", birthdayGroup);

       // Add a tab with three address fields
       TabbedControlGroup tabbedGroup = layoutControl1.AddTabbedGroup();
       LayoutControlGroup addressGroup = tabbedGroup.AddTabPage("Address Details");
       string[] dataFields = new string[] { "Country", "City", "Address" };
       foreach (string dataField in dataFields)
          CreateItemWithBoundEditor(new TextEdit(), employeesSource, dataField, addressGroup);

       // Add a tab with a photo
       LayoutControlGroup groupPhoto = tabbedGroup.AddTabPage("Photo");
       CreateItemWithBoundEditor(new PictureEdit(), employeesSource, "Photo", groupPhoto);
    }

    再次添加的时候如果需要先清除之前的item,代码如下

                layoutControlSelectBusiness.BeginUpdate();
                layoutControlSelectBusiness.Controls.Clear();
                layoutControlSelectBusiness.Root.Items.Clear();

                再次添加item的代码

               layoutControlSelectBusiness.EndUpdate();

    谢谢你提供的这篇代码,帮我解决了layoutControl多列自动排版的问题, 关键代码: 
    // Move the Last Name to the right of the First Name
    itemLastName.Move(itemFirstName, DevExpress.XtraLayout.Utils.InsertType.Right);
    再次表示感谢!

  • 相关阅读:
    solr7之solrJ的使用
    solr7.3.1在CentOS7上的安装
    nginx配置:location配置方法及实例详解
    [读书]10g/11g编程艺术深入体现结构学习笔记(持续更新...)
    liunx系统计划任务管理(at/crond调度)
    Golden Gate 概念和机制
    Oracle三大经典表连接适用情况
    Oracle索引简单介绍与示例
    Oracle RAC的日志体系
    Oracle10g RAC的简单操作
  • 原文地址:https://www.cnblogs.com/eastson/p/3854710.html
Copyright © 2011-2022 走看看