我有一个DataGridView
和一个自定义列表。我将它绑定使用:在新行后更新datagridview
datagridview.DataSource = MyList;
的问题是,每当我从一个线程新行添加到列表中,它不会在DataGridView中显示新行。有什么方法可以简单地覆盖OnNewData
事件类型DoRefresh()
,并且可能不会丢失滚动位置?
SyncList的我使用的是:
public class SyncList<T> : System.ComponentModel.BindingList<T>
{
private System.ComponentModel.ISynchronizeInvoke _SyncObject;
private System.Action<System.ComponentModel.ListChangedEventArgs> _FireEventAction;
public SyncList()
: this(null)
{
}
public SyncList(System.ComponentModel.ISynchronizeInvoke syncObject)
{
_SyncObject = syncObject;
_FireEventAction = FireEvent;
}
protected override void OnListChanged(System.ComponentModel.ListChangedEventArgs args)
{
if (_SyncObject == null)
{
FireEvent(args);
}
else
{
_SyncObject.Invoke(_FireEventAction, new object[] { args });
}
}
据我所知,你的控制不会更新,只是因为你更新'MyList'。如果您使用WinForms,[自定义对象列表视图](http://objectlistview.sourceforge.net/cs/index.html)可能会有所帮助。 – gunr2171
我正在使用SyncList,因此数据正在更新'实时'。但我必须重新分配datagridview的列表才能显示新行。 – user2320462