【问题标题】:DataGridViewComboBoxColumn behaves differently on Windows 7+ OSDataGridViewComboBoxColumn 在 Windows 7+ 操作系统上的行为不同
【发布时间】:2018-02-02 01:23:28
【问题描述】:

我在 Windows 窗体中制作了一个客户端应用程序。我使用 Windows Server 2008 R2 进行开发。

但是客户端报告了一些我无法在我的机器上重现的错误,但是当我在 Windows 7 或 10 上部署相同的解决方案时。它给了我不同的结果。

截至目前我有两个问题:

  1. DataGridViewComboBoxColumn 背景颜色是灰色的。
  2. 使用 Tabs 或 Cursors 键跨列移动时,它们会跳过组合框列。 这是最大的问题。

我用最少的代码创建了一个测试应用程序,发现测试应用程序也存在这个问题。

DataGridViewComboBoxColumn column = new DataGridViewComboBoxColumn();
{
    column.HeaderText = "CB";
    column.Name = "CB";
    column.DefaultCellStyle.BackColor = Color.White;
    //column.CellTemplate = new DataGridViewCheckBoxCell();
    column.DataSource = list;
    column.ValueType = typeof(string);

}

dataGridView1.Columns.Add(column);

dataGridView1.DataSource = dtEmp;

这是问题的截图:

Windows 10 - 请注意,尽管移动光标键,但第一列并未突出显示

Windows 2008 - 请注意,dfirst 列已突出显示,而单元格未突出显示灰显。

任何帮助将不胜感激。

【问题讨论】:

    标签: winforms datagridviewcombobox datagridviewcomboboxcell


    【解决方案1】:

    您可能会尝试将 DisplayStyle 属性更改为 Nothing 枚举值,以便您的列将被样式化并且焦点将可见。但是组合框箭头显然消失了,但这对您来说可能不是问题。

    this.Column1.DisplayStyle = System.Windows.Forms.DataGridViewComboBoxDisplayStyle.Nothing;
    

    或者尝试将FlatStyle 属性更改为Flat,这样你就会看到一个组合框箭头:

    this.Column1.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
    

    【讨论】:

    • 谢谢。这就像一个魅力 this.Column1.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-08-24
    • 2011-01-07
    • 1970-01-01
    • 1970-01-01
    • 2023-04-09
    • 2020-09-12
    • 2016-02-04
    相关资源
    最近更新 更多