Selecting item in a listbox

  • Thread starter Thread starter Mike
  • Start date Start date
M

Mike

Hello,

I have a listbox that when the form opens, it selects the
first item on the list:

Me!lstProductCategory.Selected(0) = True

When the form loads the first item in the list is being
selected (highlighted). However, when I look at the value
its NULL. If I click on the list then the proper value is
displayed. How do I have the listbox select the first item
in the listbox and have the proper value?

Thanks
 
I came across this tip this morning on the FMS, Inc
website. (www.fmsinc.com) You might find it useful:

Tip #11: Selecting the First Item in Your ListBox
Provided by: Steve Clark, Senior Project Manager

A user often wants to see something in a list box already
selected when a specific form opens or an item is selected
from another location. You can programmatically select the
first item in the list in order to accomplish this.

For a Single-Select Listbox, to automatically select the
first value, use the following code:

If IsNull(lstBox) Then
lstBox = lstBox.ItemData(0)
End If

The IsNull checks that something else isn't already
selected, to prevent changes to a value previously
selected by the user.


Hope it helps.
Terri
 
Worked perfect. Thanks again!

-----Original Message-----
I came across this tip this morning on the FMS, Inc
website. (www.fmsinc.com) You might find it useful:

Tip #11: Selecting the First Item in Your ListBox
Provided by: Steve Clark, Senior Project Manager

A user often wants to see something in a list box already
selected when a specific form opens or an item is selected
from another location. You can programmatically select the
first item in the list in order to accomplish this.

For a Single-Select Listbox, to automatically select the
first value, use the following code:

If IsNull(lstBox) Then
lstBox = lstBox.ItemData(0)
End If

The IsNull checks that something else isn't already
selected, to prevent changes to a value previously
selected by the user.


Hope it helps.
Terri

.
 
Back
Top