2015-05-11 113 views
0

我试图用一些数据填充DevExpress gridview。DevExpress GridView详细信息查看收集数据

比方说,我们有两大类:

public class ObjectA 
{ 
    public string Name { get; set; } 
    public List<ObjectB> Details1 { get; set; }  
    public List<ObjectB> Details2 { get; set; } 
} 

public class ObjectB 
{ 
    public string Name { get; set; } 
    public string Description { get; set; } 
} 

而像创建一个表单:

private List<ObjectA> datas; 

public Form1() 
{ 
    InitializeComponent(); 

    // Fill data 
    datas = ... 

    // Set datasource 
    this.gridControl1.DataSource = datas; 
    this.gridView1.BestFitColumns(); 
    this.SetRelation(); 
} 

private void SetRelation() 
{ 
    GridView customPatternView = new GridView(gridControl1); 
    customPatternView.Columns.AddField("Name").VisibleIndex = 0; 
    customPatternView.Columns.AddField("Description").VisibleIndex = 1; 
    this.gridControl1.LevelTree.Nodes.Add("CustomRelation", customPatternView); 
} 

此代码工作很好,但我obly能够显示点评详情在详细视图。 我该怎么做才能只显示Details2?

感谢

回答

0

你需要为每一个细节视图一个GridView

gridControl1.LevelTree.Nodes.Add("Details1", customPatternView); gridControl1.LevelTree.Nodes.Add("Details2", customPatternView);

0

可以使用GridControl.ShowOnlyPredefinedDetails属性。如果将此属性设置为true,则GridControl仅显示LevelTree中存在的关系。此外,使用GridControl.LevelTree.Nodes.Add方法中您的子列表属性的名称作为关系名称。
这里是例子:

private void SetRelation() 
{ 
    var customPatternView = new GridView(gridControl1); 
    customPatternView.Columns.AddField("Name").VisibleIndex = 0; 
    customPatternView.Columns.AddField("Description").VisibleIndex = 1; 
    this.gridControl1.LevelTree.Nodes.Add("Details2", customPatternView); 
    this.gridControl1.ShowOnlyPredefinedDetails = true; 
}