I keep finding ways to clear all the rows of a datagridview... but i want to keep my rows...
is there an easier way than looping through every cell to clear all the values out of the cells of the datagridview??
Printable View
I keep finding ways to clear all the rows of a datagridview... but i want to keep my rows...
is there an easier way than looping through every cell to clear all the values out of the cells of the datagridview??
Is the DGV bound to a datasource, such as a table, or is it free-standing?
I do not think you can use a datagrid view with empty rows. You may need to create your own control for that. I may be wrong.
You can do it, but it requires different things if the DGV is bound to a datatable or not. If it is not bound, then you will have to clear it manually. It's just a double loop, though. If the DGV is bound to a datatable, then you don't really want to clear the DGV. Instead, you want to clear the table fields, and that opens up a whole different set of considerations.
le sigh... ok its not bound to a datasource so i'll need to use the loop that i have.
bummer, seems like that is something there would be a 1 line command to execute
It does seem that way, and if there is such a thing it would be something like Clear, but I doubt it even exists. MS really pushes the idea that a DGV is bound to something, and in most uses it is. They did add enough functionality so that the DGV is useable without being bound, but not an excess of functionality.
Had they supplied a Clear method, it would only have made sense for unbound DGVs, since Clear on a DGV that was bound to a datatable would be pretty much undefined. It wouldn't be able to clear the table, since that would rarely be acceptable, and it certainly couldn't delete all the rows, since that would likely be a disaster. Therefore, the Clear method would work only for a distinct minority of cases. You, unfortunately, are part of that minority.