winforms datagrid在编辑时将列更改为组合框

时间:2012-04-15 04:46:40

标签: winforms datagrid combobox

我的winforms应用程序上有一个datagrid列。当用户选择特定单元格时,单元格应转向数据绑定组合框,用户可以编辑单元格。

如何在editmode上显示组合框?

2 个答案:

答案 0 :(得分:1)

您在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/

答案 1 :(得分:1)

  • 为了将细胞转换为组合框:

this.yourdatagridname.Rows [x] .Cells [y] = new DataGridComboBoxCell();

其中x,y表示您要转换的单元格

  • 为了使其可编辑:

this.yourdatagridname.Rows [x] .Cells [y] .ReadOnly = false;