Correct way to unbind a BindingSource from a DataGridView

Assigning null to the datagridview DataSource is the best way to clear data source of grid, you are correct.


If you use custom columns, set AutoGenerateColumns to false before clearing the DataSource. This will ensure your custom columns are preserved. Otherwise they will be cleared and auto generated on the next DataBind.

datagridview.AutoGenerateColumns = false; 
datagridview.DataSource = null;

Edit: Not sure why this was down voted. This is the correct solution for non auto generated columns. I have the project to prove it. I hope someone finds it useful.