Reputation: 32602
In DataGridView, when I set dataGridView.DataSource = null
or dataGridView.DataSource = false
, it removes all default setting (properties) I have set.
How it looks without setting DataSource
to null
(See Mark
column is actually DataGridViewComboBoxColumn
)
After setting DataSource
to null
or false
and load items in DataGridView:
See here Id
column is visible which I set visible false by default (from properties window). Also the Mark
column became DataGridViewTextBoxColumn
from DataGridViewComboBoxColumn
.
What I actually want: I just want to clear all rows (in other words I want to set DataGridView blank after removing records from database). Like this one:
What am I doing wrong here?
Upvotes: 4
Views: 11477
Reputation: 32445
Setting datagridview.DataSource = null
will not reset/change a columns or their properties
If you have a predefined columns(in designer) then,
please, check that line of code datagridview.AutoGenerateColumns = False
will execute properly...
Because if datagridview.AutoGenerateColumns = True
more columns will be added to predefined columns of datagridview
Upvotes: 6