CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Dec 2003
    Posts
    38

    How to highlight an entry in a listbox

    When a user clicks on an entry in a listbox it highlghts (actually the background goes to dark blue and the words turn to white). Can I do this programatically? I have a list of songs being played by mediaplayer that I remove the top entry as the song finishes playing. I would like to always keep that entry highlighted.
    I've played with about every property I can find but no luck yet.

  2. #2
    Join Date
    Aug 2003
    Location
    Buenos Aires, Argentina
    Posts
    513
    List1.ListIndex = X

    Where X is an index (begins in 0 and goes upto
    List1.ListCount-1)

  3. #3
    Join Date
    Dec 2003
    Posts
    38
    Dang that was too easy. Why couldn't I find that?? Grrr

    Thanks much

  4. #4
    Join Date
    Nov 2003
    Location
    Seattle, WA
    Posts
    265
    Also.

    Code:
      List1.Selected(Index) = True

  5. #5
    Join Date
    Dec 2003
    Posts
    38
    Is it possible to highlight more than one at a time? Ie I want the user to be able to click on one entry as the start of a range, then hold the shift key down while clicking on the end of the range so I can delete all the list entries in the range. I would like to be able to highlight all the entries in the range.

  6. #6
    Join Date
    Apr 2002
    Location
    Los Angeles, Ca
    Posts
    238
    Look into the Multi select property of the listbox control

  7. #7
    Join Date
    Nov 2003
    Location
    Seattle, WA
    Posts
    265
    Make sure multi-select is enabeld and you can select multiple things like this..

    Code:
    List1.Selected(1) = True
    List1.Selected(2) = True
    List1.Selected(3) = True
    'And so on

  8. #8
    Join Date
    Nov 2003
    Location
    Australia
    Posts
    137
    Hi,

    As a beginner I am interested in this topic.
    I am assuming that the

    List1.Selected(1) = True

    Is embedded in a Loop, where the index variable starts at 0 and goes up to the List1.ListCound - 1.
    Is this a correct assumption?

    I am also experimenting with the ListBox Style property, where
    you can set up a vbListBoxCheckBox style, each item within the ListBox has its own check box.

    In a book I am learning from it claims that vb does not allow multiple selection for vbListBoxCheckBox, however, when I run my project the gui allows me to tick off more than one item?
    If vb only allows one selection, why would the gui allow multiple ticking?

    Am I missing a step where I have to control the gui?
    TT

  9. #9
    Join Date
    Nov 2003
    Location
    Seattle, WA
    Posts
    265
    If you want to get familiar with listboxes here is a small example (using checkboxes)
    Attached Files Attached Files
    "Lose it? It means go crazy...nuts...insane...bonzo...no longer in possession of one's faculties...3 fries short of a happy meal...WACKO!!!"

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

Featured