• gridcontrol -- master-detail 绑定数据


    一、绑定DataSet

         1. 创建数据源 DataSet;DataSet中有两张表,并且主表与子表必须建立关联;

                 

    DataTable dtMaster =new DataTable();
    DataTable dtDetail= new DataTable();
    dtMaster .Columns.Add("RelationColumn");
    dtDetail.Coumns.Add("RelationColumn");
     using (DataSet ds = new DataSet())  
                {  
                    ds.Tables.AddRange(new DataTable[] {
                                                       dtMaster .Copy(), 
                                                       dtDetail.Copy() 
                                  }); // 创建表关系 DataRelation relation = new DataRelation("detailTable", ds.Tables[0].Columns[0], ds.Tables[1].Columns[0], false); ds.Relations.Add(relation); // 添加 gridControl1.DataSource = ds.Tables[0]; // 指定数据源 }

     2. ui 设置 gridControl 控件;

             gridControl中已有一默认的Gridview1 为MainView 用来显示dtMaster的数据;

             gridControl 添加一个level.在该level中创建 gridView 命名为gvDetial. 用来显示dtDetail的数据;

             修改level的名称,名称必须和数据源中定义的DataRelation的名称一致;gridcontrol 会根据MasterTable的relation来创建并显示detail的数据结构;

             将两个Gridveiw中的添加Column ,并绑定相应数据源表的字段;

    1  this.gvTable.OptionsDetail.AllowExpandEmptyDetails = true;
    2  this.gvTable.OptionsDetail.ShowDetailTabs = false;
    3  this.gvTable.OptionsPrint.ExpandAllDetails = true;
    4  this.gvTable.OptionsPrint.PrintDetails = true;
    View Code

     二、绑定实体对象

    [DataContract]
        [Serializable]
        public class PlanInfo:C_ProductPlan
        {
            public PlanInfo()
            {
                Items = new List<ProducePlanItem>();
            }
          
            [DataMember]
            public List<ProducePlanItem> Items { get; set; }
        }
    
        [DataContract]
        [Serializable]
        public class ProducePlanItem :C_ProductPlanItem
        {
           
    
            public ProducePlanItem()
            {
                ProcessConfig = new List<ProcessInfo>();
            }
          
            [DataMember]
            public List<ProcessInfo> ProcessConfig { get; set; }
    
            
    
        
    
        }
    
        
        [Serializable]
        public class ProcessInfo
        {
            public String Name{get;set;}
            public int Order{get;set;}
            public bool? IsChecked{get;set;}
            public String Memo{get;set;}
        }
    public class ProducePlanItems : ArrayList, IRelationList
        {
            public ProducePlanItems()
            {
    
            }
    
    
            #region IRelationList 成员
    
            public System.Collections.IList GetDetailList(int index, int relationIndex)
            {
                return this[index].ProcessConfig;
            }
    
            public string GetRelationName(int index, int relationIndex)
            {
    
                return "ProcessConfig";
            }
    
            public bool IsMasterRowEmpty(int index, int relationIndex)
            {
                return false;
            }
    
            public int RelationCount
            {
                get { return 1; }
            }
    
            #endregion
    
            public virtual new ProducePlanItem this[int index]
            {
                get { return base[index] as ProducePlanItem; }
            }
        }

    需要引用Dexexpress.Data.dll, 

     1.gridview-MainView 绑定到UI中定义的ProducePlanItems.

     2.添加一个level1 将level1重命名称ProcessConfig(对应上面IRelationList.GetRelationName的返回
     
     3.level1 添加 gridview2 ,需要手动设置gridview的列,可以设置gridview2的ViewCaption

     4.获取数据后将items转化成producePlanItems,并绑定到UI

  • 相关阅读:
    AFN的配置使用
    如何给另外一台电脑(同组其他成员)开发ios权限
    IAP中的坑
    如何在上架app后修改app在商店中的名字
    wordpress禁止调用官方Gravatar头像调用ssl头像链接提升加载速度
    ubuntu 杀死进程命令
    tp框架 php5.5以上版本出现”No input file specified“错误问题解决
    支付宝调用错误:Call to undefined function openssl_sign()
    浏览器下出现net::ERR_BLOCKED_BY_CLIENT的解决办法
    python 整形方法
  • 原文地址:https://www.cnblogs.com/benhua/p/5953039.html
Copyright © 2020-2023  润新知