2015-05-11 45 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; 
}