francops henri
francops henri

Reputation: 517

Datarelation with ultragrid

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

Upvotes: 0

Views: 1932

Answers (1)

S2S2
S2S2

Reputation: 8502

Firstly, you would need to populate your single Dataset with 2 queries in your datasource (which should be a stored procedure for example), to have it contain 2 DataTables, like e.g.:

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

Then, after the Dataset is filled from your DataAdapter in C# code, you would need to add DataRelations to the 2 DataTables in your Dataset, as follows:

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

Now, binding above Dataset (yourDataset) to your infragistics grid should give the UI as your desire (similar if not exact).

Give this a try, I hope this should work though I have not tried.

Upvotes: 2

Related Questions