开发者

c# DataGrid bound to List

开发者 https://www.devze.com 2023-03-31 01:53 出处:网络
I have a dataGrid bound to a List object and this works fine by calling... dgList.DataSource = carList;

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 tri开发者_如何学运维ed calling .Update() and that has no effect.

Is this possible?

The list is defined as

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


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;


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消