views:

549

answers:

1

I have a BindingList<> of objects, set to the DataSource of a BindingSource. This is set to the DataSource of a DataGridView.

I'm concerned with not causing any potential memory leaks, so wondering if there is a preferred way to unbind these connections when I am finished with the data.

I'm thinking of:

datagridview.DataSource = null;
bindingsource.DataSource = null;
bindingsource.Clear();

To re-bind:

bindingsource;DataSource = bindinglist<myObjects>;
datagridview.DataSource = bindingsource;

Is this order correct, or does it really matter? Do I have anything omitted which should be there?

Any pointers appreciated, thanks.

+1  A: 

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

Wael Dalloul