How do I set the selected item in a comboBox to match my string using C#?


Question

I have a string "test1" and my comboBox contains test1, test2, and test3. How do I set the selected item to "test1"? That is, how do I match my string to one of the comboBox items?

I was thinking of the line below, but this doesn't work.

comboBox1.SelectedText = "test1"; 
1
182
7/1/2014 7:13:27 PM

This should do the trick:

Combox1.SelectedIndex = Combox1.FindStringExact("test1")
256
1/16/2009 11:08:19 AM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon