简体   繁体   English

有什么方法可以加快DataGridView Remove的速度吗?

[英]Is there any way to speed up a DataGridView Remove?

I'm working with large sets of data and I'm storing them in a DataGridView so that the user can see that data in an application and manipulate it before it is saved into a database. 我正在处理大量数据,并将它们存储在DataGridView中,以便用户可以在应用程序中查看该数据并对其进行操作,然后再将其保存到数据库中。 Nothing is saved into the database until the user hits the save button. 除非用户点击保存按钮,否则什么都不会保存到数据库中。

The user has the ability to delete multiple rows by pressing the delete key, this works just fine if its just a few rows. 用户可以通过按Delete键删除多行,如果只有几行,则效果很好。 What if they wanted to delete a couple thousand? 如果他们想删除几千个怎么办? It takes way too long to remove that large number of rows. 删除大量行花费的时间太长。

This is how I'm currently removing them: 这是我目前删除它们的方式:

  foreach (DataGridViewRow row in dgv.SelectedRows)
       dgv.Rows.Remove(row);

Is there any way that I could just remove all of those rows in one fell swoop? 有什么办法可以一举删除所有这些行? Basically something like the Clear function, but I give it a list of rows to remove. 基本上类似于Clear函数,但我为它提供了要删除的行列表。

Try disabling GUI Update using SuspendLayout and ResumeLayout: 尝试使用SuspendLayout和ResumeLayout禁用GUI更新:

dgv.SuspendLayout();
foreach (DataGridViewRow row in dgv.SelectedRows)
{
    dgv.Rows.Remove(row);
}
dgv.ResumeLayout();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM