select last item of list box with code...

pablavo

Registered User.
Local time
Today, 15:17
Joined
Jun 28, 2007
Messages
189
Hi All,

I have a small question about a list box.

On one of my forms I have a list box. One of the column fields, which is the bound column table ID) has a reference to the forms table ID, This is so the info in the list box is relevant to the forms records. I'll be using the list box as a filter for the forms records basically.

I'm trying to find a way so that the last item is selected automatically and not the first. I've tried a couple of things including:

OnLoad Event:
Code:
lngCount = Me.lstRateOfPay.ListCount
        Me.lstRateOfPay.SetFocus
        Me.lstRateOfPay.ListIndex = lngCount

If I use only the .setfocus and type, for example, .ListIndex = 1, then it will go will set focus on item index 1. If I use the lngCount variable which counts how many items there are, I get a 7777 error, improper use of this function.

All I want to do is to write code that will automatically select the last item in the list box when the form opens.

Does anyone know how to do this?

Thanks
 
I think I've found the answer,

Code:
Me.lstRateOfPay.Selected(lstRateOfPay.ListCount - 1) = True
 
looks like you got it. just a note, the list count will be different depending on whether or not you have column heads showing.
 
Dim lvw as listiview
Set lvw = me.myLvw.object
lvw.listItems.Item(lvw.listItems.Count - 1).Selected = True
Set lvw = nothing
 

Users who are viewing this thread

Back
Top Bottom