Datagridview,禁用按钮/行 [英] Datagridview, disable button/row
问题描述
实际上有一个 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 DataGridViewRow
s 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屋!