Datagridview在从线程更新时保留waitcursor [英] Datagridview retains waitcursor when updated from thread

查看:137
本文介绍了Datagridview在从线程更新时保留waitcursor的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Windows窗体应用程序中有一个DataGridView控件。
我正在使用后台线程向网格添加行。当进程启动时,我将表单的光标更改为Waitcursor,并在结束时返回到Default。这对于表格很好,但不适用于网格。当表单的光标更改为默认值时,网格的光标不会改变,尽管光标位于表单的其余部分。



这是否与事实上我正在从后台线程更新网格? (光标正在直接从UI线程更改)。



编辑:后台进程引发事件,处理程序检查网格的InvokeRequired属性,并决定是否需要从主线程再次调用该方法。所以,实际的UI更新发生在适当的线程上。我不知道这是否意味着我是使用后台线程。 :|

解决方案

我的单线程更新我的datagrids有一些问题,其中datagrid没有重置为普通游标之后我已经等到真的。
我做的是在我去之后就是

  this.UseWaitCursor = false; 

我添加了

 code> DatagridviewFoo.Cursor = this.Cursor; 

也许这与您同样的问题


I have a DataGridView control in my Windows Forms Application. I am adding rows to the grid using a background thread. I change the form's cursor to Waitcursor when the process starts and back to Default when it ends. This works well for the form, but not for the grid. When the form's cursor is changed back to default, the grid's cursor does not change, although the cursor over the rest of the form does.

Does this have anything to do with the fact that I am updating the grid from a background thread? (The cursor is being changed from the UI thread directly).

Edit: The background process raises an event, the handler checks the InvokeRequired property of the grid and decides if it needs to "Invoke" the method again from the main thread. So, in effect the actual UI update happens from the appropriate thread. I am not sure if this means that I am "using a background thread" or not. :|

解决方案

I've had some problems doing single thread updating of my datagrids, where the datagrid did not reset to normal cursor after i've had waitcursor to true. What I did was right after i went

this.UseWaitCursor = false;

I added

DatagridviewFoo.Cursor = this.Cursor;

Maybe it's just the same problem for you

这篇关于Datagridview在从线程更新时保留waitcursor的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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