2012-03-12 45 views
0

我無法綁定一個WPF數據網格數據,看起來像這樣結合的結果:的Datagrid從數據庫

id1 id2 result 
1  10  X 

1  11  Y 

2  10  X 

2  11  Z 

其中每排有3名成員一個類的實例。所以基本上我有這些類實例的集合,我想綁定到具有可變數量列的網格(取決於「id2」列的值)。

我想要得到的結果是這樣的:

id1/id2 10 11 
1  X Y 
2  X Z 

在某些情況下,只能有一列,在其他情況下他們兩個人,所以我要後面在代碼中創建列。

我已經爲所有行和列值(Id1ItemsId2Items)創建了包裝類,但我不確定在哪裏存儲結果值以及如何創建綁定。理想情況下,我應該能夠爲第一列寫入"Id1Items.id1",第二列寫入"Id2Items.id2",但數據源集合應該如何顯示?

非常感謝。

回答

0

有一個COLUMN2但就是不使其可見,如果你只有一個

class MyDataContext 
{ 
    public string column1Name get set // bind this to the header1 
    public string column1Name get set // bind this to the header2  
    public bool ColumnTwoVisible get set // bind to this to make the column2 visible or not  

    public List<MyDataRow2> MyDataSet2 
} 


class MyDataRow2 
{ 
    public string id get set 
    public string col1 get set 
    public string col1 get set 
} 
+0

我不希望執行的財產,以使第二列可見或不可見,我寧願動態創建列,但這是一個小細節。我會嘗試使用你的想法。謝謝。 – Adrian 2012-03-13 11:04:17