CheckedListBox

  • Thread starter Thread starter Jeff
  • Start date Start date
J

Jeff

Good evening everyone,

I am just wondering if i am missing a setting for the CheckedListBox, I
added the control to my form and added a few items. I changed the property
Check On Click to true so you just have to select the once to toggle the
check box and I have the Selection Mode property set to One.
When I run the program however if I check one of the selections and then
change my mind and want to select a different item I can select it but the
first item does not uncheck. I thought that that was what the Selection
Mode property set to one was suppossed to do? Is there another setting or
will this need to be handled in code?
I was trying to look at something like selected item change,
control.items.clear() but that would actually clear all the items in the
list box?

Thanks for the help,

Jeff
 
Jeff said:
Good evening everyone,

I am just wondering if i am missing a setting for the CheckedListBox, I
added the control to my form and added a few items. I changed the property
Check On Click to true so you just have to select the once to toggle the
check box and I have the Selection Mode property set to One.
When I run the program however if I check one of the selections and then
change my mind and want to select a different item I can select it but the
first item does not uncheck. I thought that that was what the Selection
Mode property set to one was suppossed to do? Is there another setting or
will this need to be handled in code?
I was trying to look at something like selected item change,
control.items.clear() but that would actually clear all the items in the
list box?

Thanks for the help,

Jeff

Jeff,

If you are asking to only have zero or one check boxes checked at one
time, then you need to do something like the following for your
ItemCheck handler:

Private Sub CheckedListBox1_ItemCheck _
(ByVal sender As Object, _
ByVal e As System.Windows.Forms.ItemCheckEventArgs) _
Handles CheckedListBox1.ItemCheck

If (e.NewValue = CheckState.Checked) Then
For idx As Integer = 0 To CheckedListBox1.Items.Count - 1
If idx <> e.Index Then
CheckedListBox1.SetItemChecked(idx, False)
End If
Next
End If
End Sub

Generally you would use radio buttons in a group box for such operations
though.
 
Thanks Mike,

That is what I was trying to accomplish!
I would use a panel or groupbox for this which would do this also but I
wanted to look at something
that would be easy to update as items were added to the list of possible
choices. It look to me like with the checkedlistbox all you would have to
do is edit the listbox collection
whereas with a groupbox you would have to edit the form and possible have to
move things around just to add an item.

Just my thoughts why I was looking at this control.

Thanks again for your help,

Jeff
 
Back
Top