Having a problem with a checkbox

johncassell

Well-known member
Joined
Jun 10, 2007
Messages
120
Location
Redcar, England
Programming Experience
Beginner
Hi There,

can someone help me out in finding out where I am going wrong on this please...

I have a checkbox bound to a column in my table. Some rows show NULL, some show TRUE, some show FALSE.

No matter which row I select data from, it always shows the checkbox in its coloured, Intermidiate state.

Is there any advice to avoid this.

Thanks

John
 
Checkboxes are a pain. There may be a really easy way around this but I could never find it.

In the end I bound a label to that column, and this then showed True or False.

I then "bound" the checkbox to the label, i.e. at Form_Load I'd have

VB.NET:
If me.labelCheck.text = "True" Then
   me.checkbox1.checked = True
ElseIf me.labelCheck.text = "False" Then
   me.checkbox1.checked = False
End If

I then had to change the checked event to change the value of the label -
VB.NET:
Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
If me.checkbox1.checked = True Then
   me.labelCheck.text = "True"
ElseIf me.checkbox1.checked = False Then
   me.labelCheck.text = "False"
End If
    End Sub

As I say there may be an easier way around it - I could never get on with the checkbox and didn't really want to spend a lot of time working out what was going on - the above worked and I left it at that :D
 
Hi John dont go for 3 to 4 lines of coding for this simple operation
u just try this , very intresting

Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
Me.Label1.Text = Me.CheckBox1.Checked
End Sub
 
Hi John dont go for 3 to 4 lines of coding for this simple operation
u just try this , very intresting

Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
Me.Label1.Text = Me.CheckBox1.Checked
End Sub

to do that properly:
VB.NET:
Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
  Me.Label1.Text = Me.CheckBox1.Checked.ToString
End Sub

But I have never had a problem with binding a checkbox to the dataset, simply add the checkbox then bind it to the dataset and the field
 
But I have never had a problem with binding a checkbox to the dataset, simply add the checkbox then bind it to the dataset and the field

problem I've found is that if you do a new row, the checkbox is greyed out, but ticked. A few users I've had assumed this meant it was already checked, but it doesn't mark it as checked (if that makes any sense).
According to the properties at design time, Checked = False

The only way around this I found was to put into Form_Load; me.checkbox1.checked=false
which then the form starts up and the checkbox is clear.
 
Back
Top