hog Posted September 26, 2003 Posted September 26, 2003 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?? Quote My website
AlexCode Posted September 26, 2003 Posted September 26, 2003 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... Quote Software bugs are impossible to detect by anybody except the end user.
*Gurus* divil Posted September 26, 2003 *Gurus* Posted September 26, 2003 He was asking about a checkbox, not a combobox :) If you set the AutoCheck property to false, I think that will effectively disable it against user input. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
AlexCode Posted September 26, 2003 Posted September 26, 2003 iiiiii ... sorry ... :D Quote Software bugs are impossible to detect by anybody except the end user.
hog Posted September 26, 2003 Author Posted September 26, 2003 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.... Quote My website
hog Posted September 29, 2003 Author Posted September 29, 2003 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 Quote My website
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.