自定义xtraGrid mater/ detail 数据结构显示
xtraGrid 本身支持DataSet master/detail的数据直接帮定.可以参看其文档,
当然也可以继承接口:DevExpress.Data.IRelationList  定义自己的数据源.

还有可以动态来帮定detail的数据.- 通过事件触发的方式.
根据今天我的探索,写一点动态帮定经验.

我有两个实体类
1. orderItem 继承了myCollectionBase(来之于CollectionBase)
2. item (明细类)
自定义xtraGrid mater/ detail 数据结构显示[DBTableAttr("SalesOrder")]
自定义xtraGrid mater/ detail 数据结构显示    
public class orderItem : myCollectionBase
    }


master的数据源也是一个myCollection对象 : _orders

自定义xtraGrid mater/ detail 数据结构显示//获取并帮定master数据源的代码
自定义xtraGrid mater/ detail 数据结构显示
try
            }


detail数据源则是_orders[i] ,它本身也是一个Collection对象.

先用设计器把想显示的数据列设计好
自定义xtraGrid mater/ detail 数据结构显示

gridControls 都必然有一个MainView,主视图,你可以通过设计器修改主视图,我就设定gridView1为它的主视图(见上图).

接着通过Create a new level 来创建一个新级别,所有的级别都比MainView至少低一个级别.

我把第二级别定义为orderItems而它使用orderDetail视图来实现数据.

MasterRowGetRelationCount  这个事件只要定义e.RelationCount = 2; 就可以了,这样在界面上才可以看到数据前有+号.

这个事件主要是定义gridView1的关联级别是那一个(注意是orderItems,而不是orderDetail)
自定义xtraGrid mater/ detail 数据结构显示        private void gridView1_MasterRowGetRelationName(object sender, DevExpress.XtraGrid.Views.Grid.MasterRowGetRelationNameEventArgs e)

自定义xtraGrid mater/ detail 数据结构显示 private void gridView1_MasterRowGetChildList(object sender, DevExpress.XtraGrid.Views.Grid.MasterRowGetChildListEventArgs e)
        }


自定义xtraGrid mater/ detail 数据结构显示private void gridView1_MasterRowEmpty(object sender, DevExpress.XtraGrid.Views.Grid.MasterRowEmptyEventArgs e)
        }

完成了.运行试试看.

相关文章: