2012-02-27 22 views
0

我有這樣一個數據表:的DataRelation用的UltraGrid

 
Quantity Price Date  Comment 
50   20  10/15 Buy 160 
40   15  10/15 Buy 160 
60   14  10/15 Buy 160 
35   22  10/16 Buy 276 
44   16  10/16 Buy 276 
78   13  10/16 Buy 276 
96   19  10/16 Buy 276 
23   2  10/16 Buy 276 

我想看看這一場的UltraGrid當母親表

 
Date Comment 
10/15 Buy 160 
and 
10/16 Buy 276 

和子表是:

 
50   20  10/15 Buy 160 
40   15  10/15 Buy 160 
60   14  10/15 Buy 160 
and 
35   22  10/16 Buy 276 
44   16  10/16 Buy 276 
78   13  10/16 Buy 276 
96   19  10/16 Buy 276 
23   2  10/16 Buy 276 

我知道我應該使用datarelation,但我真的不知道如何 謝謝你的他LP

+0

聯繫供應商 – leppie 2012-02-27 10:53:59

+0

您是否在談論擁有兩種不同的超網格?或者你在談論可擴展行(在超網格中稱爲band)?您可以從數據庫中取回信息並使用LINQ對數據進行分組並將網格綁定到您的結果。 – 2012-06-26 16:49:46

回答

2

首先,您需要填寫您的單一Dataset在你的數據源2 queries(這應該是例如存儲過程),將它包含2 DataTables,例如像:

Select Date, Comment From <yourTable>; -- DataTable1 
Select Quantity, Price, Date, Comment From <yourTable>; -- DataTable2 

然後,該數據集是從您的DataAdapterC#代碼後,你需要在你的Dataset添加DataRelations到2 DataTables,如下所示:

DataColumn[] parentColumns=null; 
DataColumn[] childColumns=null; 

parentColumns = new DataColumn[] { yourDataset.Tables[0].Columns["Date"], yourDataset.Tables[0].Columns["Comment"]}; 

childColumns = new DataColumn[] { yourDataset.Tables[1].Columns["Date"], yourDataset.Tables[1].Columns["Comment"]}; 

yourDataset.Relations.Add(new DataRelation("Date-Comment-Relation", parentColumns, childColumns)); 

現在,綁定數據集(yourDataset)到您的infragistics網格應該爲您的用戶界面(類似,如果不是確切的)。

給這個嘗試,我希望這應該工作,雖然我還沒有嘗試過。

+0

另外不要忘記檢查你的ViewStyle是否是MultiBand – Steve 2012-02-27 12:24:55

+0

是的,當然......謝謝@Steve – VS1 2012-02-27 12:26:33

+0

好的非常感謝你的答案的第一部分我想知道我是如何輕鬆地讓這2個datable,我可以試試循環並說: 如果datatable [「日期」]是不同的做一個新的數據 但有什麼辦法只是削減datable與datable相同的日期? – 2012-02-27 12:33:11