【发布时间】:2018-04-30 06:40:24
【问题描述】:
我想显示一个表格。表格数据必须预先计算,计算量大。结果表也很长。 我想提供对部分数据的访问,而另一部分是在后台计算的。
我为计算编写了后台工作程序,为显示编写了 DataGridView。有时工作人员通过 ProgressChangedEvent 提交新行。我试图在底部添加这些行。 当我尝试在底部添加新行时,我的问题就开始了。我的 UI 卡住了。
这是我初始化 DataGridView 的方式:
private void InitDataGridView()
{
BindingList<TableRow> tableRows = new BindingList<TableRow>();
dataGridView.DataSource = tableRows;
}
这是我如何在 ProgressChangedEvent 底部添加新行
private void UpdateDataGridView (List<Items> newItems)
{
BindingList<TableRow> dataSource = (BindingList<TableRow>)this.dataGridView.DataSource;
foreach (var item in newItems)
dataSource.Add(new TableRow(item));
}
我认为这个问题是因为添加一行会重新绘制表格。 但我没有找到用于 BindingList 的 AddRange 或临时停止渲染的机制。
有什么建议吗?
【问题讨论】:
-
看看this post也可以实现
IBindingList,它可以停止引发ListChanged事件。 -
看起来很有趣。感谢指导。
标签: c# winforms user-interface datagridview