3

I've got confusion of setting / getting selected indexes of combobox fields inside.

    this.Parameter.DataSource = lambdacat.Dict();
    {
        foreach (DataGridViewRow row in LimView.Rows)
        {
            //( (ComboBox)row.Cells[1] ) ???
        }
    }

yes , this doesn't work :)

thank you

Upendra Chaudhari
  • 6,473
  • 5
  • 25
  • 42
cnd
  • 32,616
  • 62
  • 183
  • 313

1 Answers1

4

You can use

(row.Cells[1] as DataGridViewComboBoxCell).Value == yourvalue;

and get the selected value as

(row.Cells[1] as DataGridViewComboBoxCell).FormattedValue

To set a default selected value

(row.Cells[1] as DataGridViewComboBoxCell).Value =(row.Cells[1] as DataGridViewComboBoxCell).Items[yourneededindex] 
V4Vendetta
  • 37,194
  • 9
  • 78
  • 82
  • I've got a string array there , if yourvalue is a string it doesn't works :( – cnd Apr 26 '11 at 07:45
  • If you want to add the items of the array use **(row.Cells[1] as DataGridViewComboBoxCell).Items.Add(arrayval)** while looping the array – V4Vendetta Apr 26 '11 at 08:00
  • 2
    I presume you mean a default select, so you can use **(row.Cells[1] as DataGridViewComboBoxCell).Value =(row.Cells[1] as DataGridViewComboBoxCell).Items[yourneededindex]** – V4Vendetta Apr 26 '11 at 08:26