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

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

问题描述

我有一些数据的表格上一个DataGridView。第1列包含删除行按钮。我们怎样才能禁用此按钮,或根据某些条件的整个行,因此该行不能删除?

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?

推荐答案

有实际上是一个的在MSDN方法文档做的正是这一点。

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

编辑:增加了一些其他建议

Added some other suggestions.

您可以使按钮栏不可见。

You can make the button column invisible.

或者,如果你只是想禁用某些行的删除,你可以把真正的还是在每个的DataGridViewRow 取值标签财产和你的按钮事件处理只删除被设置为假的。你可能只改变了电池的前景和背景颜色,使其看起来禁用着色在这个很可能在 CellFormatting 事件处理程序或东西,以便进行结合本你不必通过环和手的颜色吧。

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天全站免登陆