|
-
Aug 28th, 2003, 12:58 PM
#1
Thread Starter
Addicted Member
How do I make a Checkbox readonly? [resolved]
I want to keep the checkbox enabled (to keep the white bg/black fg checkmark symbol), but I want it to be readonly. If I set enable=false, then everything gets grayed out.
Any ideas how I can set all the checkboxes on my form to readonly, but maintain the enable state to preserve the same look as normal checkboxes?
Last edited by Shurijo; Aug 28th, 2003 at 01:35 PM.
-Shurijo
-
Aug 28th, 2003, 01:05 PM
#2
Ya ya Baby!!!Me is Back
when the user click you can just do a code to but back the value of it.
if chkBox.value = true then chkbox.value = true
Something like that
-
Aug 28th, 2003, 01:12 PM
#3
Thread Starter
Addicted Member
I thought about that but I'd have to store the value (checked or unchecked) for each checkbox on my form (dozens of them) and then use the same event handler for all checkbox_clicks, etc. I was wondering if there was some easier way.
-
Aug 28th, 2003, 01:36 PM
#4
Thread Starter
Addicted Member
I ended up doing it that way:
PHP Code:
...
'loop through all checkboxes
'ckb = checkbox object
ckb.Tag = LCase(CStr(ckb.Checked))
AddHandler ckb.CheckedChanged, New System.EventHandler(AddressOf checkbox_CheckedChanged)
....
Private Sub checkbox_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim ckbox As CheckBox
ckbox = CType(sender, CheckBox)
ckbox.Checked = IIf(LCase(ckbox.Tag) = "true", True, False)
End Sub
-
Aug 28th, 2003, 01:37 PM
#5
Sleep mode
Set them to Checked [True] and put this code into your form .
VB Code:
Private Sub CheckBox1_CheckedChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
CheckBox1.CheckedChanged, CheckBox2.CheckedChanged,
CheckBox3.CheckedChanged
CheckBox1.CheckState = CheckState.Checked
CheckBox2.CheckState = CheckState.Checked
CheckBox3.CheckState = CheckState.Checked
End Sub
-
Aug 28th, 2003, 02:09 PM
#6
Frenzied Member
You can define a subclass of checkbox and declare a readonlycheckstate property for it, and in checkstate changed event set it back to original state. In case you need to change the checkstate all you have to do is changing that property.
BTW, why you need lots of readonly check boxes? are they bound to a datasource or something that you dont want to be edited? if so you can disable edit of the underlying datasource. Clear enough?
VB Code:
Public Class ReadOnlyCheckBox
Inherits CheckBox
Dim c_state As CheckState
Public Property ReadOnlyState() As CheckState
Get
Return c_state
End Get
Set(ByVal Value As CheckState)
c_state = Value
MyBase.CheckState = Value
End Set
End Property
Public Sub New(ByVal state As CheckState)
c_state = state
MyBase.CheckState = state
End Sub
Private Sub ReadOnlyCheckBox_CheckStateChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.CheckStateChanged
MyBase.CheckState = c_state
End Sub
End Class
Last edited by Lunatic3; Aug 28th, 2003 at 02:20 PM.
'Heading for the automatic overload'
Marillion, Brave, The Great Escape, 1994
'How will WE stand the FIRE TOMORROW?'
Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979
-
Aug 28th, 2003, 02:35 PM
#7
Thread Starter
Addicted Member
BTW, why you need lots of readonly check boxes? are they bound to a datasource or something that you dont want to be edited? if so you can disable edit of the underlying datasource. Clear enough?
Editing is disabled from the underlying datasource, but the client wants white checkboxes rather than grayed out checkboxes.
-
Aug 28th, 2003, 02:42 PM
#8
Frenzied Member
The checkboxes wont be grayed out if bound to a readonly datasource, will they?
Anyway, i think the idea of custom control will be a good aproach. You can bind the ReadOnlyState property to the datasource.
'Heading for the automatic overload'
Marillion, Brave, The Great Escape, 1994
'How will WE stand the FIRE TOMORROW?'
Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|