Consulting

Results 1 to 9 of 9

Thread: how to highlight the first value in a listbox

  1. #1

    how to highlight the first value in a listbox

    does anyone have some ideas on how to highlight the first item in a listbox when the userform initializes?

    thanks!!

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    Private Sub Userform_Initialize()

    Me.ListBox1.ListIndex = 0
    End Sub
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    thank you very much.
    does this initallly select 0 or just highlight it?
    erik

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    How are you differentiating selecting from highlighting?
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    good question. all i thought i was attempting to do is just highlight the first item in the listbox, not actually have it selected. i am not sure if it being selected is an issue (or not). i will have to play with it and see what, if anything, happens in a negative way to my rudimentary code.
    i woulndt think so.

    erik

  6. #6
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    If you only wanted it highlighted, not selected, you must understand those two things to be different. So I ask again, what do you mean by select and highlight?
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  7. #7
    i do understand they are different. i was just looking to have it highlighted when the form initialized. as i am new, i am trying to learn all the different ways of accomplishing what i would like to do.
    erik

  8. #8
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    If you're trying to learn, then build a userform and add a listbox and try some things. for example:
    [VBA]
    Private Sub CommandButton1_Click()
    MsgBox ListBox1.Value
    End Sub

    Private Sub Userform_Initialize()
    Me.ListBox1.ListIndex = 0
    End Sub
    [/VBA]

    Results should answer some questions for you.
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  9. #9
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Well, actualy I am saying that they are NOT different. Highlighted is just a visible stance on what is selected, so they are the same thing, or more accurately, they are differnt aspects of the same thing. That is why I asked as I were thinking of something slightly different.

    If you do see them as the same thing as I do, there are no implications that I can see. Selecting an item in the listbox does highlight, and it will trigger the Listbox Click event, but other than that, nothing untoward.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

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