locked
Code to check which Listbox is selected RRS feed

  • Question

  • Hi All

    I have a series of listboxes on a Userform.

    I am trying to write a Select Case statement that will ascertain which listbox has been selected from the series of listboxes. 

    I have tried Select case listbox, listbox_selected etc.

    I can find lots of help about selecting items, but not selecting listboxes.

    Thank you in advance.

    Regards

    Wednesday

    Monday, June 6, 2011 7:35 AM

Answers

  • This is a kind of programming style done in VB4, VB5 and VB6 and also in VBS where often the click on the listbox was used.

    It is not done anymore.

    However, in a way you can still use it.

     Private Sub ListBox1_SelectedIndexChanged(sender As System.Object,
       e As System.EventArgs) Handles ListBox1.SelectedIndexChanged,
       ListBox2.SelectedIndexChanged
     Select Case (DirectCast(sender, ListBox)).Name
     Case "ListBox1"
     '
     Case "ListBox2"
     '
     End Select
     End Sub
    

     

     


    Success
    Cor


    Monday, June 6, 2011 8:06 AM

All replies

  • This is a kind of programming style done in VB4, VB5 and VB6 and also in VBS where often the click on the listbox was used.

    It is not done anymore.

    However, in a way you can still use it.

     Private Sub ListBox1_SelectedIndexChanged(sender As System.Object,
       e As System.EventArgs) Handles ListBox1.SelectedIndexChanged,
       ListBox2.SelectedIndexChanged
     Select Case (DirectCast(sender, ListBox)).Name
     Case "ListBox1"
     '
     Case "ListBox2"
     '
     End Select
     End Sub
    

     

     


    Success
    Cor


    Monday, June 6, 2011 8:06 AM
  • Hi Cor

    Thank you very much for your reply.  It works!!!

    I would never have come up with this solution.

    A very grateful

    Wednesday

    Monday, June 6, 2011 9:08 AM