我如何禁用一个WinForms数据网格中的纽扣电池? [英] How do I disable a button cell in a WinForms DataGrid?

查看:155
本文介绍了我如何禁用一个WinForms数据网格中的纽扣电池?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个DataGridView控制和内DataGridViewButtonCell单元格列WinForms应用程序。当我点击这些按钮中的一个,它启动一个后台任务,我想,直到任务完成以禁用按钮。

I have a WinForms application with a DataGridView control and a column of DataGridViewButtonCell cells within that. When I click on one of these buttons, it starts a background task, and I'd like to disable the buttons until that task completes.

我可以禁用DataGridView控件,但它给任何指示该按钮被禁用。对,让我一个方法,我希望用户看到按钮被禁用,并且注意到了,当按钮被再次启用该任务已经完成了。

I can disable the DataGridView control, but it gives no visual indication that the buttons are disabled. I want the user to see that the buttons are disabled, and to notice that the task has finished when the buttons are enabled again.

加分单独禁用按钮,这样我就可以离开,而任务运行启用按钮之一。 (请注意,我实际上并不能给出奖励积分。)

Bonus points for a method that allows me to disable the buttons individually, so I can leave one of the buttons enabled while the task runs. (Note that I can't actually give out bonus points.)

推荐答案

下面是到目前为止,我已经找到了最好的解决方案。这 MSDN文章给出,增加了一个启用一个单元格类的源代码属性。

Here's the best solution I've found so far. This MSDN article gives the source code for a cell class that adds an Enabled property.

它的工作原理相当不错,但有两个陷阱:

It works reasonably well, but there are two gotchas:


  1. 您有设置上的任何细胞Enabled属性后,电网失效。它表明,在示例代码,但是我错过了。

  2. 这只是一个视觉变化,设置Enabled属性实际上并没有启用或禁用按钮。用户仍然可以点击它。我可以执行单击事件之前检查enabled属性,但它似乎也当用户在其上点击被搞乱的外观。相反,我只是禁用整个电网。这工作好了我,但我更喜欢的方法,让我禁用某些按键没有禁用整个网格。

有在 DataGridView的常见问题解答

这篇关于我如何禁用一个WinForms数据网格中的纽扣电池?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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