终于让它工作了!为了将来参考,这是我使用的:
首先调用此方法来初始化手动绑定,使用BindingSource
:
private BindingSource bindingSource ;
private void InitUserListArea()
{
_bindingSource = new BindingSource();
_bindingSource.DataSource = tempUsers;
_labelUserListRoleValue.DataBindings.Add("Text", _bindingSource, "Role");
_labelUserListNameValue.DataBindings.Add("Text", _bindingSource, "Name");
_labelUserListLastAccessValue.DataBindings.Add("Text", _bindingSource, "LastAccess");
_dataRepeaterUserList.DataSource = _bindingSource;
}
然后获取数据(在我的情况下来自网络服务)并用数据填充列表。填充列表后,或发生任何更改时:
private void RefreshDataRepeater()
{
if (_dataRepeaterUserList.InvokeRequired)
{
_dataRepeaterUserList.Invoke((Action)(() => { RefreshDataRepeater(); }));
return;
}
_bindingSource.DataSource = null;
_bindingSource.DataSource = tempUsers;
_dataRepeaterUserList.DataSource = null;
_dataRepeaterUserList.DataSource = _bindingSource;
_dataRepeaterUserList.Refresh();
}