ListView Question

G

Guest

I have a textbox that holds a product code called txtDtlProdCode.Tex
I insert the values into SQLCE and populate a list view lstOrdersDt
I then check to see that the product code in txtDtlProdCode.Text is in lstOrdersDtl and throw a message if it exists
I then want to find and set the lstOrderDtl.FullRowSelect to the particular item in lstOrdersDtl. I want to do this without a DB Call. Can I

Can i use something along the lines of...
lstOrdersDtl.Items(lstOrdersDtl.SelectedIndices(0)).SubItems(0).Text()
 
P

Peter Foot [MVP]

If you want the text of the listitem (not one of the subitems you would
use:-

lstOrdersDtl.Items(index).Text

What you should add to your code is a check that there is a selected index -
otherwise you'll get an exception e.g.

Dim strSelectedItemText As String

If lstOrdersDtl.SelectedIndices.Count > 0 Then
'text of currently selected list item
strSelectedItemText =
lstOrdersDtl.Items(lstOrdersDtl.SelectedIndices(0)).Text
Else
'empty string
strSelectedItemText = ""
End If

Is this what you are trying to achieve?

Peter
 
P

Peter Foot [MVP]

In that case you can loop through the listview items and check the text
against your textbox value. If it matches you can set the item Selected
property to true. Something like this:-

For Each lvi As ListViewItem in listView1.Items

If lvi.Text = txtBox.Text Then
lvi.Selected = True
Exit For
End If

Next


Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Please help 1
List View Q 2
ListView problems 3
ListView Control 6
Listview subitems !HELP! 2
ListView bug 4
listview columnwidth to largest subitem? 4
ListView Selected Item 9

Top