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

Select listview item from combobox

Status
Not open for further replies.

barbola

Technical User
Joined
Feb 27, 2003
Messages
1,132
Location
CA
I would like the user to select an item in a combo box and have that item highlighted in my listview.

How do I do this? The reverse works
Me.cboCustomer.Text = lvwCustDetail.SelectedItem

but lvwCustDetail.SelectedItem = Me.cboCustomer doesn't work.

thanks.
 
Hi,

The reason the code you're using isn't working is that it's setting the text of the selecteditem in the Listview to the text of the combobox.

You can use the .FindItem method of the listview if you like. An example of that would be:
Code:
Private Sub Combo1_Click()
Dim itmList As ListItem 'object to hold found item's reference

Set itmList = ListView1.FindItem(Combo1.Text, lvwText, , lvwWholeWord) 'set the object to the found item. Combo1.Text is the value to be found, lvwText is the constant that tells to match on the listviews default text property and lvwWholeWord tells it to match on the whole word.
itmList.EnsureVisible 'makes sure the listview scrolls to the found item
itmList.Selected = True 'selects it
ListView1.SetFocus 'sets focus to the listview so you can see the selection.
End Sub
This might not be the easiest way to do it but it's the way I would do it.

Hope this helps

HarleyQuinn
---------------------------------
Get the most out of Tek-Tips, read FAQ222-2244 before posting.
 
Yes thank you. I'll try the finditem method.

barb
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top