I have a text box for the user to enter an id number. The user then clicks on a button and if a matching number is found in the id field of the listView, that item becomes selected. Any ideas how I do this??
Printable View
I have a text box for the user to enter an id number. The user then clicks on a button and if a matching number is found in the id field of the listView, that item becomes selected. Any ideas how I do this??
what do you mean by "id field of the listView"? is it the text of the list item the id?
Sorry, didn't explain very well. The database I'm using has a field called ID which is a number. How do I select the record in the ListView by clicking on a button.
Hope that makes a bit more sense??
well you could use something like this to find the index of the item... only if the ID is the text of the listview item, and only if its the first colum... you can probably change this a bit to make it work for your code. I dont think .NET itself provides a way to search:
VB Code:
Public Shared Function ListViewFind(ByVal txt As String, ByVal lvw As ListView) As Integer Dim li As ListViewItem For Each li In lvw.Items If li.Text = txt Then Return li.Index End If Next Return -1 End Function
Thanks for the code. I can now get the index. As you've probably guessed I'm a newbie!
So is there any way I can use this index to automatically select the item in the listview??
Thanks in advance.
Think I've cracked it at last:
Me.ListView1.Items.Item(intIndex).Selected = True
Thanks for your help MrPolite.