为DataGridView ComboBox设置选定项目失败

时间:2011-04-25 13:07:03

标签: c# .net winforms

我对设置/获取组合框字段的选定索引感到困惑。

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

是的,这不起作用:)

谢谢

1 个答案:

答案 0 :(得分:4)

您可以使用

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

并将所选值设为

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

设置默认选定值

(row.Cells[1] as DataGridViewComboBoxCell).Value =(row.Cells[1] as DataGridViewComboBoxCell).Items[yourneededindex]