Seven
Seven

Reputation: 441

How to manually select combo box in C#.Net?

i would like to ask a question. i have a five button and one combo box in my windows form. combo box have 5 items to select in their collection.

eg.

1.John

2.Steve

3.Seven

4.Jhone

5.Eistein

like that.

i want to manually select the items in combo box with button's event. when i click Seven button,that combo box will automatically select John to Seven. Or select Eistein that combo box's select item will automatically select Seven to Eistein. How can i do that?

Please let me know if you can do that. Thanks your for your time. :)

Upvotes: 0

Views: 725

Answers (1)

CodeCaster
CodeCaster

Reputation: 151588

Use FindStringExact:

private void einsteinButton_Click(object sender, EventArgs e)
{
    int item = ComboBox.FindStringExact("Einstein");
    if (item >= 0)
        ComboBox.SelectedItem = item;
}

Upvotes: 2

Related Questions