Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I'm sure there must be an easy way but I must be missing it:(

 

How can I make a checkbox read only? I have tried using Enabled=False but this greys out the control. I want the checkbox to remain looking like it does when it is enabled but not allow the user to change it??

My website
Posted

Ok ... this is not the cutess thing but it will work.

The ComboBox dropdown button will desapear and you won't be able to change the text on it...

 

Make you combobox control, inheriting from the System.Windows.Forms.ComboBox and add the following code:

 

   Private Sub ComboBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles ComboBox1.KeyPress

       If IsReadOnly Then e.Handled = True

   End Sub

   Dim _IsReadOnly As Boolean
   Public Property IsReadOnly() As Boolean
       Get
           Return _IsReadOnly
       End Get
       Set(ByVal Value As Boolean)
           If Value Then
               Me.ComboBox1.DropDownStyle = ComboBoxStyle.Simple
           Else
               Me.ComboBox1.DropDownStyle = ComboBoxStyle.DropDown
           End If
       End Set
   End Property

 

 

You'll have to change the names if they don't apply...

Software bugs are impossible to detect by anybody except the end user.
Posted

LOL:)

 

Ok I have set the AutoCheck property to False which has the following result.

 

When the form opens the user can click the checkbox and no check appears which is what I want. But when the app changes the checkbox to checked and then the user clicks it the check can be removed!!

 

DOH....

My website
Posted

Along with using the AutoCheck property set to False I have not placed this code on the Click Event of the CheckBox which resolces the problem.....allbeit messy :(

 


 Private Sub chkRemoveP1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles chkRemoveP1.Click

       Dim chkCheckBox As CheckBox = DirectCast(sender, CheckBox)

       If chkCheckBox.Checked Then

           chkCheckBox.Checked = True

       End If

End Sub

My website

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...