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

Steve
  • 213,761
  • 22
  • 232
  • 286
francops henri
  • 507
  • 3
  • 17
  • 29
  • Are you talking about having two different ultragrids? Or are you talking about expandable rows (called bands in ultragrid)? You can probably pull back the information from the DB and use LINQ to group the data and bind the grid to your results. – Jeff B Jun 26 '12 at 16:49

1 Answers1

2

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.

S2S2
  • 8,322
  • 5
  • 37
  • 65
  • Also don't forget to check that your ViewStyle is MultiBand – Steve Feb 27 '12 at 12:24
  • Ok thanks a lot for the first part ofyour answer I wonder how I cam make this 2 datable easily, I can try by looping on it and say : if datatable["Date"] is different do a new datatble But there any way to just cut the datatable by to datable with the same date ? – francops henri Feb 27 '12 at 12:33
  • @francopshenri Add a using statement as `using System.Linq;` in your code file and see if any of the `LINQ` operations of the `DataTable` work for you to do this!! OR there must be some method of System.Data.Datatable itself that should help you e.g. the `Select()` method of `DataTable`. – S2S2 Feb 27 '12 at 13:45