Reputation: 3515
Inside windows form there are textbox 'txtSearch' and button 'btnOk'.
Below is listbox which is populated with articles from database.
I have following code which takes user input and based on that string put selection on matched row inside listbox. Problem is that it matches only exact string using FindStringExact
method.
How to implement to match part of name article not whole name listed?
int index = listBoxArticles.FindStringExact(txtSearch.Text) + 0;
string str = Convert.ToString(txtSearch.Text);
listBoxArticles.SelectedIndex = index;
Upvotes: 0
Views: 97
Reputation: 2806
You needn't to convert the txtSearch.Text
to string
, because it is already a string
.
For your needs, use the method FindString()
of the listbox, see MSDN
May be it is more efficient, to directly query the database with the search text. this would improves the performance and limits the data that are tranfered to the client.
Upvotes: 1