locked
Visual Basic 2010 and checklistbox

    Pertanyaan

  • 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

    23 September 2010 14:47

Jawaban

  •   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
    • Ditandai sebagai Jawaban oleh Liliane Teng 30 September 2010 9:13
    23 September 2010 15:14
    Moderator

Semua Balasan

  •   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
    • Ditandai sebagai Jawaban oleh Liliane Teng 30 September 2010 9:13
    23 September 2010 15:14
    Moderator
  • 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

     

    23 September 2010 22:06
  • 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
    30 September 2010 9:14