我的 winforms 应用程序上有一个 datagrid 列。当用户选择特定单元格时,该单元格应变为数据绑定的组合框,并且用户可以编辑该单元格。
如何在编辑模式上显示组合框?
this.yourdatagridname.Rows[x].Cells[y] = new DataGridComboBoxCell();
其中 x,y 表示要转换的单元格
this.yourdatagridname.Rows[x].Cells[y].ReadOnly = false;
EditingControlShowing 事件中有什么?
void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
BindingSource bindingSource = this.dataGridView1.DataSource as BindingSource;
Person person = bindingSource.Current as Person;
BindingList<personType> bindingList = this.FindPersonTypes(person);
DataGridViewComboBoxEditingControl comboBox = e.Control as DataGridViewComboBoxEditingControl;
comboBox.DataSource = bindingList;
}
参考:http ://www.timvw.be/2007/01/17/exploring-datagridviewcomboboxcolumn-databinding/