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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Programmatically select item in listbox?

Status
Not open for further replies.

CraigBest

Programmer
Aug 1, 2001
545
US
Hi,

I have a listbox in which I want to identify a specific value and automatically select it when the form opens.

I already figured out I should (probably) use the i = listbox1.FindString ("SearchString") method in the form_load sub to identify the index of the item in the listbox. But now, how to I use the index I have to set that item to selected? Can't seem to figure it out. I figure it probably has something to do with the Items collection but I haven't found the right command phrase yet. And the documentation is not helpful on this.

Any help is greatly appreciated.

CraigHartz


CraigHartz
 
You could try:
[tt]
ListBox1.SelectedIndex = ListBox1.FindString("SearchString")
[/tt]

Hope this helps

[vampire][bat]
 
Thanks, that sounds good. I'll give it a try.


CraigHartz
 
Try SetSelected.
Example:
Code:
Me.lbx_AccessList.SetSelected(Me.lbx_AccessList.FindStringExact( _
   rsLineDesc.Fields("Line_Description").Value), True)
I took this from a program so pardon the names. It was in a loop the moved through the recordset rsLineDesc.
djj
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top