Results 1 to 5 of 5

Thread: [RESOLVED] Auto Select Item In ListBox

  1. #1

    Thread Starter
    Frenzied Member arpan_de's Avatar
    Join Date
    Oct 2005
    Location
    Mumbai, India
    Posts
    1,394

    Resolved [RESOLVED] Auto Select Item In ListBox

    A Form has a ListBox wherein only 1 item is visible at a time. Usually when a ListBox is scrolled using the mouse, the previous/next item becomes visible to him but the item that becomes visible DOESN'T get selected. The user has to click the item explicitly to select it (of course, if a user uses the keyboard to scroll the ListBox, the items get selected too but that's a different matter).

    What I want is when a user scrolls the ListBox using his mouse, the item that becomes visible to him should automatically get selected as well.

    Can this be accomplished? If yes, how?

    Note that the ListBox doesn't include CheckBoxes.


    ARPAN

    IF YOU HAVE AN APPLE & I HAVE AN APPLE AND WE EXCHANGE THE APPLES, THEN YOU & I WILL STILL HAVE ONE APPLE BUT IF YOU HAVE AN IDEA & I HAVE AN IDEA AND WE EXCHANGE OUR IDEAS, THEN EACH OF US WILL HAVE TWO IDEAS!

    NOTHING IS IMPOSSIBLE IN THIS WORLD.....EVEN THE WORD IMPOSSIBLE SAYS I'M POSSIBLE!

    PRACTICE MAKES A MAN PERFECT BUT NOBODY IS PERFECT; SO WHY PRACTICE?

  2. #2
    Interweb adm/o/distrator Paul M's Avatar
    Join Date
    Nov 2006
    Location
    Australia, Melbourne
    Posts
    2,306

    Re: Auto Select Item In ListBox

    Code:
    Private Sub List1_Scroll()
    Dim i As Long
    For i = 0 To List1.ListCount - 1
    List1.Selected(i) = True
    Next
    End Sub
    Something like that possibly but when is the item added exactly? because once you have scrolled to the bottom you cant go any further.

  3. #3

    Thread Starter
    Frenzied Member arpan_de's Avatar
    Join Date
    Oct 2005
    Location
    Mumbai, India
    Posts
    1,394

    Re: Auto Select Item In ListBox

    I tried your code mate but selecting any item in the ListBox directly selects the last item in the ListBox. Actuually I must confess that I framed my question a bit wrongly. I should have stated it clearly that when scrolling, I want to retrieve the item to which the user has scrolled to & not necessarily select that item & this code does that:

    Code:
    Private Sub List1_Scroll()
        MsgBox List1.List(List1.TopIndex)
    End Sub
    If the ListBox has 5 items, say Item1.....Item5, then scrolling down with the mouse, if Item2 becomes visible in the ListBox, the message box says Item2. If the user scrolls to Item3 making it visible, then the message box displays Item3 so on & so forth. This is exactly what I wanted.

    Once again sorry for the oversight.


    ARPAN

    IF YOU HAVE AN APPLE & I HAVE AN APPLE AND WE EXCHANGE THE APPLES, THEN YOU & I WILL STILL HAVE ONE APPLE BUT IF YOU HAVE AN IDEA & I HAVE AN IDEA AND WE EXCHANGE OUR IDEAS, THEN EACH OF US WILL HAVE TWO IDEAS!

    NOTHING IS IMPOSSIBLE IN THIS WORLD.....EVEN THE WORD IMPOSSIBLE SAYS I'M POSSIBLE!

    PRACTICE MAKES A MAN PERFECT BUT NOBODY IS PERFECT; SO WHY PRACTICE?

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Auto Select Item In ListBox

    So, is this resolved for you?

  5. #5

    Thread Starter
    Frenzied Member arpan_de's Avatar
    Join Date
    Oct 2005
    Location
    Mumbai, India
    Posts
    1,394

    Re: Auto Select Item In ListBox

    yes....yes....sorry....forgot to mark it [RESOLVED]....will do it now....better late than never, what say? ;-)


    ARPAN

    IF YOU HAVE AN APPLE & I HAVE AN APPLE AND WE EXCHANGE THE APPLES, THEN YOU & I WILL STILL HAVE ONE APPLE BUT IF YOU HAVE AN IDEA & I HAVE AN IDEA AND WE EXCHANGE OUR IDEAS, THEN EACH OF US WILL HAVE TWO IDEAS!

    NOTHING IS IMPOSSIBLE IN THIS WORLD.....EVEN THE WORD IMPOSSIBLE SAYS I'M POSSIBLE!

    PRACTICE MAKES A MAN PERFECT BUT NOBODY IS PERFECT; SO WHY PRACTICE?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width