I would like to implement a "Group By" for my datatable. Has any one any suggestions?
update:
c#, .net 2.0
The grouping indicator is added by the drawCallback function, which will parse through the rows which are displayed, and enter a grouping TR element where a new group is found. A click event handler is added for the grouping rows to allow the grouping order to be restored as well as ordering by any other column.
A DataTable can be queried with LINQ, just as any other IEnumerable<T> list. Note: DataTable does not implement IEnumerable<T>. You have to call AsEnumerable, which is an extension method for DataTable, to obtain a wrapper that implements that interface.
After you create a DataTable and define its structure using columns and constraints, you can add new rows of data to the table. To add a new row, declare a new variable as type DataRow. A new DataRow object is returned when you call the NewRow method.
You can use the linq extensions in the System.Data.DataSetExtensions assembly:
DataTable t = //
var groups = t.AsEnumerable()
.GroupBy(r => r.Field<T>("columnName"))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With