0

I have a datatable like this :

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

I want to see this in a ultragrid where the mother table are

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

and the child table are :

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

I know that I should use datarelation but I don't really know how Thanks fro your help

4

1 回答 1

2

首先,您需要在数据源(例如应该是一个存储过程)中填充您的单曲Dataset2 queries使其包含 2 DataTables,例如:

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

然后,在从您DataAdapterC#代码中填充数据集后,您需要将 DataRelations 添加到2 DataTables您的 中Dataset,如下所示:

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));

现在,将 Dataset (yourDataset) 上方的绑定到您的基础架构网格应该会按照您的意愿提供 UI(如果不准确,则类似)。

试一试,我希望这应该可以工作,虽然我还没有尝试过。

于 2012-02-27T12:16:07.237 回答