使用backgoundworker和datagridview时出现错误消息 [英] Error message when working with backgoundworker and datagridview

查看:117
本文介绍了使用backgoundworker和datagridview时出现错误消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Backgroundworker以避免在处理长循环时冻结应用程序.

I am trying to use Backgroundworker to avoid application freezing when working with a long loop.

该循环正在删除某些内容来自datagridview的记录.

The loop is deleting some  records from a datagridview.

首先,用于删除行的代码未放置在后台工作器中,并且一切正常.

At first place the code used to delete rows was not placed in a background worker and everything worked fine. 

然后,我将代码复制粘贴到后台工作人员,然后放置"BackgroundWorker1.RunWorkerAsync()";来运行backgorundworker,并且还运行"Control.CheckForIllegalCrossThreadCalls = False".在表单加载事件中.

Then I copy-pasted the code to the backgroundworker, I placed  "BackgroundWorker1.RunWorkerAsync()" to run the backgorundworker and also "Control.CheckForIllegalCrossThreadCalls = False" in the form load event.

问题是我得到了索引在数组的边界之外".错误消息.

The problem is that I get a "Index was outside the bounds of the array." error message.

这是什么问题?

推荐答案

问题可能出在代码中的某个地方,您可以在其中访问带有索引的DataGridView的Rows集合索引值超出了行范围的大小.这可能是因为您要删除行,但索引移位不正确.

Problem possibly is that somewhere in your code where you access Rows collection of the DataGridView with index the index value is outsize of the range of rows. This might be because you are deleting rows, but the index is not shifted correctly.

如果您可以提供您的代码示例,则可以更轻松地搜索实际问题.

If you can provide sample of your code, it would be easier to search the actual problem.


这篇关于使用backgoundworker和datagridview时出现错误消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆