If i have a ultrawingrid with derived columns 9columns calculated from other columns), how do i get all the rows (with header row) in a datatable? Thanks
Hi Sandeep,
There's no built-in way to convert the grid's data into a DataTable. You would have to loop through the grid columns and build your DataTable, then loop through the rows and populate your DataTable rows.
Here's a very simple-case code example I created:
UltraGridBand band = this.ultraGrid1.DisplayLayout.Bands[0]; DataTable dt = new DataTable(); foreach (UltraGridColumn gridColumn in band.Columns) { dt.Columns.Add(gridColumn.Key, gridColumn.DataType); } foreach (UltraGridRow row in this.ultraGrid1.Rows) { List<object> cellValues = new List<object>(row.Cells.Count); foreach (UltraGridCell cell in row.Cells) { cellValues.Add(cell.Value); } dt.Rows.Add(cellValues.ToArray()); }
Thanks..If there is more than 1 band.Just trying to make the code more generic.
Yes, you just need to change the row loop.
You can use one of these:
The first one will get all of the data rows. The second will skip any rows that are hidden or filtered out.
foreach (UltraGridRow row in this.ultraGrid1.Rows.GetAllNonGroupByRows())foreach (UltraGridRow row in this.ultraGrid1.Rows.GetFilteredInNonGroupByRows())
I see. The code you gave to take data from the grid into datatable does not seem to work if there is groupby column..in this case only the groupby rows are added..Any way to make the code work for grids with groupby columns
Well... it's not possible to create a DataTable for a multi-band grid. You would need multiple tables and a DataSet. And then you would have to figure out how you want to deal with creating the Relationship. It would depend on the data - you would need some key fields to hook up the parent and child data. It's much more complex than just creating a single DataTable.