How can we block the user from unchecking a DataGridView checkbox?
Posted
by hawbsl
on Stack Overflow
See other posts from Stack Overflow
or by hawbsl
Published on 2010-02-15T10:31:34Z
Indexed on
2010/04/30
14:27 UTC
Read the original article
Hit count: 232
We have a DataGridViewCheckBox column bound to a boolean property in our class.
The property setter has some logic which says that under certain conditions a True flag cannot be changed, ie, it stays checked forever. This is on a per record basis. So the entire column can't be readonly, only certain rows.
Pseudo code:
Public Property Foo() As Boolean
Get
Return _Foo
End Get
Set(ByVal value As Boolean)
If _Foo And Bar And value = False Then
//do nothing, in this scenario once you're true, you stay true
Else
_Foo = value
End If
End Set
End Property
Databinding is handling all of this fine, except that the checkbox is visibly cleared when it's clicked. Then, of course, when the binding / setter is fired (as you move off that cell) it is restored to its checked status per the underlying logic. Ultimately it doesn't matter too much but it's a clumsy bit of UI.
How can we intercept the user's click and keep it checked?
© Stack Overflow or respective owner