locked
Visual Basic 2010 and checklistbox

    Question

  • I am using a checkedlistbox in VB 2010, with the following choices

    • None / No Medical Expertise
    • Burns
    • Physical Trauma
    • Gas
    • Other

    What I need to do is if the user checks true None / No Medical Expertise I need to prevent them from selecting any of the other options. However the user can select as many as or as few as any of the other options providing  they dont select None / No Medical Expertise.

    Can any help me with the code for this problem

    Thursday, September 23, 2010 2:47 PM

Answers

  •   Private Sub CheckedListBox1_ItemCheck(ByVal sender As Object, ByVal e As System.Windows.Forms.ItemCheckEventArgs) Handles CheckedListBox1.ItemCheck
    
        'ASSUMES "NONE/NO MEDICAL EXPERTISE" IS ALWAYS FIRST ITEM IN LIST
        'IF FIRST ITEM IS BEING CHECKED
        If e.Index = 0 And e.NewValue = CheckState.Checked Then
          For i As Integer = 1 To (CheckedListBox1.Items.Count - 1)
            CheckedListBox1.SetItemChecked(i, False)
          Next
        Else
          If e.Index <> 0 Then
            CheckedListBox1.SetItemChecked(0, False)
          End If
        End If
      End Sub
    

    Matt Kleinwaks - MSMVP MSDN Forums Moderator - www.zerosandtheone.com
    • Marked as answer by Liliane Teng Thursday, September 30, 2010 9:13 AM
    Thursday, September 23, 2010 3:14 PM

All replies

  •   Private Sub CheckedListBox1_ItemCheck(ByVal sender As Object, ByVal e As System.Windows.Forms.ItemCheckEventArgs) Handles CheckedListBox1.ItemCheck
    
        'ASSUMES "NONE/NO MEDICAL EXPERTISE" IS ALWAYS FIRST ITEM IN LIST
        'IF FIRST ITEM IS BEING CHECKED
        If e.Index = 0 And e.NewValue = CheckState.Checked Then
          For i As Integer = 1 To (CheckedListBox1.Items.Count - 1)
            CheckedListBox1.SetItemChecked(i, False)
          Next
        Else
          If e.Index <> 0 Then
            CheckedListBox1.SetItemChecked(0, False)
          End If
        End If
      End Sub
    

    Matt Kleinwaks - MSMVP MSDN Forums Moderator - www.zerosandtheone.com
    • Marked as answer by Liliane Teng Thursday, September 30, 2010 9:13 AM
    Thursday, September 23, 2010 3:14 PM
  • Matt,

    your assumption is correct None / No Medical Expertise will always be the first option. Thank you for your help will try it out during the day

     

    Thursday, September 23, 2010 10:06 PM
  • Hello DavidAUST,

    Thanks for your post.

    What about your problem? When you come back, if you think it provides no help, please unmark and follow up. Thanks.

    Best regards,
    Liliane
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please mark the replies as answers if they help and unmark them if they provide no help. Welcome to the All-In-One Code Framework! If you have any feedback, please tell us. Thanks
    Thursday, September 30, 2010 9:14 AM