【问题标题】:How do I Highlight a DataGridViewComboBoxCell when it has focus?有焦点时如何突出显示 DataGridViewComboBoxCell?
【发布时间】:2016-04-07 23:31:28
【问题描述】:

我有一个DataGridView 和一个DataGridViewComboBoxColumn。当我浏览任何单元格时,它们会突出显示。我的问题是当我浏览 ComboBoxColumn 单元格时,它们不会突出显示。这是我创建列的代码。

        DataGridViewCellStyle GridStyleCombo = new DataGridViewCellStyle();
        DataGridViewCell cell2 = new DataGridViewComboBoxCell();
        DataGridViewComboBoxColumn col1 = new DataGridViewComboBoxColumn()
        {
            CellTemplate = cell2,
            Name = "boundProfile",
            HeaderText = "Promotion Bound Profile",
            DataPropertyName = "BoundProfile",
            DataSource = new BindingSource(DA.GetProfiles(), null),
            FillWeight = 10,
            AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill,
            SortMode = DataGridViewColumnSortMode.Automatic,
            DefaultCellStyle = GridStyleCombo,
            DisplayMember = "Key",
            ValueMember = "Value"
        };

有没有办法以某种方式突出显示这些单元格?我已经尝试更改DataGridViewCellDataGridViewCellStyle 的选择颜色。

【问题讨论】:

    标签: c# datagridview combobox selection-color


    【解决方案1】:

    我遇到了同样的问题。

    我发现如果我将网格的EditMode 属性设置为EditOnEnter,当我输入单元格时,组合框单元格会突出显示。

    它还解决了在下拉组合框出现之前必须在单元格上单击两三次的问题。

    此解决方案的唯一问题是,当EditMode 属性设置为EditOnEnter,并且您通过单击行标题选择一行时,将选择整行,但只会选择一个单元格在编辑模式。这会导致以下情况:如果您尝试通过选择行标题来删除行,则无法删除该行,因为删除键实际上是发送到正在编辑的单元格,而不是行。

    【讨论】:

    • 我从来都不喜欢使用row headers,所以这个问题并不是真正的问题。非常感谢您的建议,刚刚对其进行了测试,它就像一个魅力,尽管我确实通过在datagrid cellclick event 中这样做来解决它 if (dataGrid.Columns[e.ColumnIndex] is DataGridViewComboBoxColumn && validRow) { dataGrid.BeginEdit(true ); ((ComboBox)dataGrid.EditingControl).DroppedDown = true; }
    猜你喜欢
    • 1970-01-01
    • 2012-06-17
    • 1970-01-01
    • 2017-04-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-06
    • 1970-01-01
    相关资源
    最近更新 更多