Himanshu
Himanshu

Reputation: 32602

Setting DataSource of DataGridView to null/false removes all default settings of DataGridView

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)

enter image description here

After setting DataSource to null or false and load items in DataGridView:

enter image description here

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:

enter image description here

What am I doing wrong here?

Upvotes: 4

Views: 11477

Answers (1)

Fabio
Fabio

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

Related Questions