How to search the listbox for a word or part of a word? For example: in the textbox1 we write the word "man" and click on the "Search" button and we need to find a word or part of a word in listbox1 and go to the line with this word. And so by clicking the "Search" button again, so that the next line containing this word is found. And if there is no further line with this word in the list, then you need to search in a circle and go to the first line with this word in the listbox. That is, so that the search takes place in a circle in the listbox, by pressing the "Search" button. (If possible, explain how to beginner). In general, you need the same function as in the "Find Next" button in Notepad.
I did it like this, but it works incorrectly, passes through all the options in the listbox and stops at the last one:
private void buttonFindNext_Click(object sender, EventArgs e) { Form1 main = this.Owner as Form1; if (main != null) for (int i = 0; i < main.listBox1.Items.Count; i++) { if (main.listBox1.Items[i].ToString().ToLower().Contains(textBoxSearch.Text)) { main.listBox1.SetSelected(i, true); } } } How to make it to find only one option, and by pressing the "find further" button, I proceeded to the next found text, which was entered into textBoxSearch?