【问题标题】:Editing Combobox item in Datagridview in C#在 C# 中的 Datagridview 中编辑 Combobox 项
【发布时间】:2012-11-25 12:22:20
【问题描述】:

我在 Winform 中有一个 Datagridview。其中一列是Combobox。除了能够从下拉列表中选择条目之外,是否可以设置属性以便用户可以输入。

我可以在 Combobox 项目上通过属性窗口进行以下更改:

AutoCompleteMode.SuggestAppend;
AutoCompleteSource.CustomSource;
DropDownStyle : Dropdown;

谢谢

【问题讨论】:

    标签: c# winforms datagridview datagridviewcomboboxcell


    【解决方案1】:

    这样的事情可能会有所帮助:-

    private void DataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
    {
        if (DataGridView1.CurrentCell.ColumnIndex == yourComboBoxColum)
        {
            ComboBox combo = e.Control as ComboBox;
    
            if (combo == null)
                return;
    
            combo.DropDownStyle = ComboBoxStyle.DropDown;
        }
    }
    

    【讨论】:

    • 非常感谢,它确实使组合框单元格可编辑。但是,由于我在虚拟模式下设置了 Datagridview,我无法将新值推送到基础类对象。它总是恢复到以前的值。知道为什么会发生吗?
    • 帮不了你,我没用过虚拟模式。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-28
    • 2015-07-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多