Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set Selected item of ComboBox in C# Windows Forms?

I am trying to set selected item of comboBox on click event of DataGrid, but I could not. I have googled and tried different ways but without success.

For me SelectedIndex is working, but I could not find the index of items in ComboBox, so I could not select the item.

Not working code:

for (int i = 0; i < cmbVendor.Items.Count; i++)

    if (cmbVendor.Items[i].ToString() == Convert.ToString(gridView1.GetFocusedRowCellValue("vVendor")))
    {
        cmbVendor.SelectedIndex = i;
        break;
    }
like image 828
Azhar Avatar asked Feb 22 '12 13:02

Azhar


1 Answers

At last I found it out. It's:

cmbVendor.Text = Convert.ToString(gridView1.GetFocusedRowCellValue("vVendor"));

The SelectedText property is for the selected portion of the editable text in the textbox part of the combo box.

like image 73
Azhar Avatar answered Oct 18 '22 14:10

Azhar