List Box

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • michels287
    New Member
    • Mar 2008
    • 20

    List Box

    I have six list boxes in my VB6 project and two buttons.

    The first button's job is to select the next item in the current list box. Now that I am adding more listboxes how can I modify the following command so that it will always pertain to the current list box?

    If List1.ListIndex > 0 Then
    List1.ListIndex = List1.ListIndex - 1
    End If

    Also how can I create a way so that when the second button is pressed the first value in the next list box is chosen?

    Thanks!
  • debasisdas
    Recognized Expert Expert
    • Dec 2006
    • 8119

    #2
    If you want to select the next item it must be +1 not -1.

    Comment

    • QVeen72
      Recognized Expert Top Contributor
      • Oct 2006
      • 1445

      #3
      Hi,

      When you Select a ListBox, and Then Click on the Command button, your Focus should have shifted to the Command, you will not get Previously selected List Box. To find the last selected Control , you have to Declare a Formlevel variable say:

      Dim intL as Integer

      And in GotFocus of all the ListBoxes, populate that Variable with some Number (say 1 for list1, 2-for list2 and so on..)
      and in command Click use a select case and set that ListBox's ListIndex to next Index..

      REgards
      Veena

      Comment

      • Killer42
        Recognized Expert Expert
        • Oct 2006
        • 8429

        #4
        Just one thing - since you're using VB6, I'd recommend using a control array for the listboxes. It makes your code much simpler, since you just change the index to refer to different controls, rather than having to write code for each one.

        Comment

        • michels287
          New Member
          • Mar 2008
          • 20

          #5
          Thanks guys.

          I have heard of arrays and have been reading on them since my post.

          So if I make an array, I have to declare the array? Then I can type code with your recommendations to shift through the list boxes once the command is pressed?

          What does it mean to type a select case?

          Thanks again.

          Comment

          • Killer42
            Recognized Expert Expert
            • Oct 2006
            • 8429

            #6
            Originally posted by michels287
            I have heard of arrays and have been reading on them since my post.

            So if I make an array, I have to declare the array? Then I can type code with your recommendations to shift through the list boxes once the command is pressed?
            You don't declare a control array like you do an array of variables. In the form designer, just copy a control, then paste it back in. VB will ask if you want to make them an array.

            Originally posted by michels287
            What does it mean to type a select case?
            Not sure what you're asking.

            Comment

            Working...