单击C#DataGridViewComboxColumn时不会执行任何操作

单击C#DataGridViewComboxColumn时不会执行任何操作,c#,winforms,datagridview,C#,Winforms,Datagridview,我对这里发生的事情感到非常困惑。我有一个DataGridviewComboBoxColumn,我想把它当作一个组合框(显然)。我有以下代码: designer.cs中的代码: this.PurposeCol.DataPropertyName = "Purpose"; this.PurposeCol.DisplayStyle = System.Windows.Forms.DataGridViewComboBoxDisplayStyle.ComboBox; this.PurposeCol.Heade

我对这里发生的事情感到非常困惑。我有一个
DataGridviewComboBoxColumn
,我想把它当作一个组合框(显然)。我有以下代码:

designer.cs中的代码:

this.PurposeCol.DataPropertyName = "Purpose";
this.PurposeCol.DisplayStyle = System.Windows.Forms.DataGridViewComboBoxDisplayStyle.ComboBox;
this.PurposeCol.HeaderText = "Purpose";
this.PurposeCol.Name = "PurposeCol";
this.PurposeCol.Resizable = System.Windows.Forms.DataGridViewTriState.True;
this.PurposeCol.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
this.PurposeCol.Width = 78;
表单页上的构造函数:

PurposeCol.ReadOnly = false;
PurposeCol.DataSource = tripPurposeComboBox.Items;  //Verified that this line fills the datasource with 14 items          
PurposeCol.DisplayMember = "ItemText";
PurposeCol.ValueMember = "ItemValue";

问题是当我点击它时什么也没发生。显示的文本是我所期望的,我可以确认
数据源中有14个项目,但我似乎无法显示任何其他项目。是否需要在
DataGridviewComboBoxColumn
之前设置一个特殊设置,以使其像一个
ComboBox

将列的
ReadOnly
属性设置为
False
,但要确保
DataGridView.ReadOnly
属性也设置为
False
(默认情况下)


如果设置为
True
,它将覆盖列上的
只读
属性,您将无法打开下拉列表。

要将其用作可编辑的组合框,您需要在编辑控件时为组合框单元格实现验证事件 例如

并实现cbo_验证和SpacingComBox_SelectedIndexChanged

void cbo_验证(对象发送方,CancelEventArgs e)私有void SpacingComBox\u SelectedIndexChanged(对象发送方,事件参数e)


你试过双击单元格吗?它是否打开但您没有任何项目?下拉箭头高亮显示,并显示单个值,但单击或双击它时不会发生任何事情。我还有一个用于
datagridview
的click事件处理程序,它不会被触发。它确实有项,但没有打开。我想我以前也遇到过类似的问题,请确保没有其他可能中断的相关事件,并确保单元格未标记为只读(当我说“确保”时,请在运行时使用调试器检查)。此datagridview上有许多事件处理程序,可能会导致问题。也许我可以编写代码强制组合框打开?它最终成为另一个类(
DataPropertyName
)的依赖项,该类没有set属性,只有get。谢谢你的帮助!这两项都设置为false,但这并没有解决问题。但是,这段代码中有大量的事件处理程序可能会导致问题。我得继续挖
dataGridView1.ReadOnly = false;
 private void datagrid_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
    {
        if (datagrid.CurrentCell.ColumnIndex == 4)
        {
            if (e.Control.GetType() == typeof(DataGridViewComboBoxEditingControl))
            {
                DataGridViewComboBoxEditingControl cbo = e.Control as DataGridViewComboBoxEditingControl;
                cbo.DropDownStyle = ComboBoxStyle.DropDown;

                cbo.Validating += new CancelEventHandler(cbo_Validating);
                cbo.SelectedIndexChanged += new EventHandler(SpacingComBox_SelectedIndexChanged);
            }

        }
    }