为DataGridView ComboBox设置选定项目失败
我已经混淆了设置/获取combobox字段的选定索引。
this.Parameter.DataSource = lambdacat.Dict(); { foreach (DataGridViewRow row in LimView.Rows) { //( (ComboBox)row.Cells[1] ) ??? } }
是的,这不起作用:)
谢谢
您可以使用
(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]