highlight listview item from mysql search statement then get the index

Reverend Jim commented: Unclear title and question. -2

Recommended Answers

All 6 Replies

i want to search item from listview using search query then highlight the selected item in the listview

Let's try to narrow this down. I'm guessing that you have a database that you want to be able to search. The user is presented with a listview containing predefined search strings. The user (possibly) selects an item in the listview. This causes the database to be searched for the selected string. The last part "then highlight the selected item in the listview" doesn't make sense to me because the selected item is automatically highlighted.

There are probably several other interpretations of your request so please provide more detail.

After beating my head into the wall 1,000 times over when working with listview, I have discovered an easy way.


Dim index as String

For Each sItem As ListViewItem In DatabaseListView.SelectedItems
       index = sItem.Text

'this will select the item at the start of the row that is clicked. 
'you can use that item to then reference your database.

Am I missing something here? By definition, the item that is clicked is already selected.

My post above singles out the first column in the row. Listviews are pain do deal with when working with databases. This allows you to used the selected row to perform a query.

If there is one thing I have learned in over 30 years of dealing with users and program specs it is this - if you don't know what your program is supposed to do then you had better not start writing it.

That's why I am trying to get the OP to more clearly define the problem. For example, the OP has not even specified what mode the listview is in. You might assume Detalis or List, but in the absence of specific information and a clear definition of the problem, supplying code is (at least in my opinion - not that I have anything better to do at the moment ;)) counterproductive.

One other gem I heard from the users more times than I liked was "that's just what I asked for but not what I wanted"

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.