Default First Row  in List Box

Benyaw
Benyaw used Ask the Experts™
on
how do i make the first record in my list box selected....

i've tried [itemdata] & [selected] but no joy... i urgently need to solve this..

any help appreciated

thanks
benyaw
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Scott McDaniel (EE MVE )Infotrakker Software
Most Valuable Expert 2012
Top Expert 2014

Commented:
To select the first row:

Me.YourListview.Selected(0) = True
Dale FyeOwner, Dev-Soln LLC
Most Valuable Expert 2014
Top Expert 2010

Commented:
Scott,

That will select the first item, but if you immediately print the value of the list, it will still be null.  I use

Me.lst_Numbers = Me.lst_Numbers.ItemData(-Me.lst_Numbers.ColumnHeads)

you could use 0 as the index # for ItemData, but if you have ColumnHeads turned on, it will not work, so I generally just use this all of the time.
Infotrakker Software
Most Valuable Expert 2012
Top Expert 2014
Commented:
Dale,

If you have set ColumnHeaders = True, then you are correct that you would get a NULL value. However, you can simply change the 0 to a 1 to select the first row:

If Me.List0.ColumnHeaders = True Then
  Me.List0.Selected(1) = True
Else
  Me.List0.Selected(0) = True
End If

Dale FyeOwner, Dev-Soln LLC
Most Valuable Expert 2014
Top Expert 2010

Commented:
Actually, you need two lines, one to set the value and the other to actually select the item in the list:

Me.lst_Numbers = Me.lst_Numbers.ItemData(-Me.lst_Numbers.ColumnHeads)
Me.lst_Numbers.selected(-Me.lst_Numbers.ColumnHeads) = true

Dale FyeOwner, Dev-Soln LLC
Most Valuable Expert 2014
Top Expert 2010

Commented:
Scott,

you are correct, my bad.  Have not had my coffee yet.  I was thinking you had to set the value of the list as well, so I guess the 2nd line would suffice for all circumstances.

Me.lst_Numbers.selected(-Me.lst_Numbers.ColumnHeads) = true



Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial