I have an UltraGrid that is populated from a database query. I need to clear the data rows from the grid without losing the columns or affecting the grid layout. I suspect this is easy but am unable to find a solution. Please help.
Thanks,
Assuming your query is in the form of a DataTable, call DataTable.Rows.Clear, which will remove all the rows but leave the schema intact.
Thanks Brian!
Yes, but that datatable is set locally in the loading function, so after exiting it, I don't have acces to it.
Doesn't the grid have any clear content or clear datasource method ?
mismar said:Yes, but that datatable is set locally in the loading function, so after exiting it, I don't have acces to it.
Why not simply store a reference to it in a local variable?
Or, you could get it from the grid.DataSource property.
mismar said:Doesn't the grid have any clear content or clear datasource method ?
No, there's no such method on the grid.
You could, of course, set the grid's DataSource to null, and this would remove all rows and columns from the grid. But this will have no effect on the underlying DataSource itself.
Or you could select all of the rows in the grid and call grid.DeleteSelected to delete all of the rows from the grid and the data source. But it's sort've odd to use a UI component method to do something that is easier to do in code. It's also less efficient and requires more coding than deleting the rows from the data source directly.
Thanks!
I've used grid's datasource property to clear it.