Lee Armstrong
Lee Armstrong

Reputation: 11452

c# DataGrid bound to List

I have a dataGrid bound to a List object and this works fine by calling...

dgList.DataSource = carList;

However I have code that updates the carList on background threads by polling servers and also deletes based on age. The datagrid does not seem to update at all, I tried calling .Update() and that has no effect.

Is this possible?

The list is defined as

List<Car> = carList = new List<Car>();

Upvotes: 0

Views: 247

Answers (2)

Random Dev
Random Dev

Reputation: 52270

You have to rebind the data with DataBind again

as for WinForms: have you tried to reset the source again? If not use a BindingSource instead of the raw list.

Upvotes: 1

Grant Thomas
Grant Thomas

Reputation: 45083

Refresh won't work because it only redraws the control:

Forces the control to invalidate its client area and immediately redraw itself and any child controls.

The simplest solution is likely to rebind using DataSource again:

dgList.DataSource = carList;
carList.Add(car);
dgList.DataSource = null;
dgList.DataSource = carList;

Upvotes: 2

Related Questions