mr+sina admin
Posts : 428 Points : 763 Reputation : 1 Join date : 2013-08-07
| Subject: code search dar listbox C# Sun Aug 11, 2013 6:33 pm | |
| - Code:
-
private void Form1_Load(object sender, System.EventArgs e) { listBox1.Items.Add("Angelina"); listBox1.Items.Add("Isabella"); listBox1.Items.Add("Sarah"); }
private void button1_Click(object sender, System.EventArgs e) { // Set the search string: string myString = "Isabella"; // Search starting from index -1: int index = listBox1.FindString(myString, -1); if (index != -1) { // Select the found item: listBox1.SetSelected(index,true); // Send a success message: MessageBox.Show("Found the item \"" + myString + "\" at index: " + index); } else MessageBox.Show("Item not found."); | |
|