Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set selected items for DataGridView ComboBox failed

Tags:

c#

.net

winforms

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

like image 860
cnd Avatar asked May 22 '26 08:05

cnd


1 Answers

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] 
like image 173
V4Vendetta Avatar answered May 24 '26 23:05

V4Vendetta



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!