I am trying to populate a DataGridView based on the selected item in a ComboBox, I have this part working.
However, I need to be able to clear the grid before adding the new data from a new item rather than it just adding on to the end.
How do I clear a DataGridView before adding items to it?
By default, users can edit the contents of the current DataGridView text box cell by typing in it or pressing F2.
Set the DataGridViewColumn. Visible property to false .
The DataGridView control provides a customizable table for displaying data. The DataGridView class allows customization of cells, rows, columns, and borders through the use of properties such as DefaultCellStyle, ColumnHeadersDefaultCellStyle, CellBorderStyle, and GridColor.
Firstly, null the data source:
this.dataGridView.DataSource = null;
Then clear the rows:
this.dataGridView.Rows.Clear();
Then set the data source to the new list:
this.dataGridView.DataSource = this.GetNewValues();
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