PDA

View Full Version : how to highlight the first value in a listbox



drawworkhome
11-22-2009, 08:57 AM
does anyone have some ideas on how to highlight the first item in a listbox when the userform initializes?

thanks!!

Bob Phillips
11-22-2009, 09:09 AM
Private Sub Userform_Initialize()

Me.ListBox1.ListIndex = 0
End Sub

drawworkhome
11-22-2009, 09:23 AM
thank you very much.
does this initallly select 0 or just highlight it?
erik

Bob Phillips
11-22-2009, 09:38 AM
How are you differentiating selecting from highlighting?

drawworkhome
11-22-2009, 09:46 AM
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

Bob Phillips
11-22-2009, 10:23 AM
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?

drawworkhome
11-22-2009, 03:47 PM
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

lucas
11-22-2009, 04:00 PM
If you're trying to learn, then build a userform and add a listbox and try some things. for example:

Private Sub CommandButton1_Click()
MsgBox ListBox1.Value
End Sub

Private Sub Userform_Initialize()
Me.ListBox1.ListIndex = 0
End Sub


Results should answer some questions for you.

Bob Phillips
11-22-2009, 04:01 PM
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.