Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Scroll to the selected item in ListBox

Status
Not open for further replies.

sidanshu

Programmer
Aug 21, 2001
29
0
0
CA
Hi
I have a list box ,data coming from table and i need to select a default value in that.the Value does get highlighted but the listbox can show only 3 items at a time and if it is 5th or 6th or even more ..item then i have to scroll downmyself to see the selectde item.I need to directly setfocus on that and i should see the selected item as soon as list box gets focus.
i tried setfocus and even topindex property to set it as first item- to se it but does not work.
Any help appreciated.
Thanks
Sid
 
Did you try this?
___
[tt]
Private Sub List1_Click()
On Error Resume Next
List1.TopIndex = List1.ListIndex
End Sub
[/tt]
 
Thanks Hypetia - it works and actualy i was using the topindex property at a liitle wrong place - which i figured out later- so it worked too.but ur code saved my 3 lines.
Anyway now i have another simple problem thati am not able to get he current selected record number in the listbox- is there any way to get that.
See my problem is that in DB records are not in sorted order- but by list box property set to sorted=true, they display sorted in listbox.Now when i search db to find a particular record and want to set it as default(or set its listindex true) i can't do that because its index is diff in the list box and DB(DB # comes in my recordset which i use to find the default value.)
i don't know if i made it clear for u or not- if need more clarification please let me know.
Thanks
Sid
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top