Datagridview,禁用按钮/行 [英] Datagridview, disable button/row

查看:338
本文介绍了Datagridview,禁用按钮/行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个datagridview在一个表单与一些数据。第一列包含删除行的按钮。我们如何根据某些条件禁用此按钮或整行,因此该行不能被删除?

解决方案

实际上有一个 HowTo 在MSDN上正好做到这一点。



编辑:添加了一些其他建议。



您可以使按钮列不可见。或者如果您只想禁用某些行的删除,则可以在每个 DataGridViewRow 中放入true或false 标签属性,并且在您的按钮事件处理程序中,您只会删除设置为false的那些。您可以将此与仅更改单元格的前景和背景颜色相结合,使其看起来处于禁用状态,这种着色可能在 CellFormatting 事件处理程序中完成你不必循环并手工着色。


I have a datagridview on a form with some data. The 1st column contains button for deleting the row. How can we disable this button or the entire row based on some condition, so the row cannot be deleted?

解决方案

There's actually a HowTo on MSDN doing exactly this.

Edit: Added some other suggestions.

You can make the button column invisible.

Or if you only want to disable deletion of certain rows you could put in true or false in each DataGridViewRows Tag property and in your button event handler you only delete the ones that are set to false. You could possibly combine this with just changing the foreground and background colours of the cell to make it look disabled, this colouring in could probably be done in the CellFormatting event handler or something so that you don't have to loop through and colour it in by hand.

这篇关于Datagridview,禁用按钮/行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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