winformsdatagridviewcomboboxdatagridviewcomboboxcell

DataGridViewComboBoxColumn behaves differently on Windows 7+ OS


I've made a client application in Windows Forms. I've used Windows Server 2008 R2 for development.

However client has reported few bugs which I am not able to reproduce on my machine but when I deploy same solution on Windows 7 or 10. It gives me different results.

As of now I now two problems:

  1. DataGridViewComboBoxColumn backcolour turns out to be gray.
  2. When moving across the columns using Tabs or Cursors keys, they skip combo box column. This is biggest problem.

I've created a test application with minimal code and found that this problem persists with test app as well.

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;

Here is screenshot of problem:

Windows 10 - Notice that despite moving cursor key, first column is not highlighted
enter image description here
Windows 2008- Notice that dfirst column is highlighted and cells are not grayed out.
enter image description here

Any help would be greatly appreciated.


Solution

  • You might try to change DisplayStyle property to Nothing enum value so that your column will by styled and focus will be visible. However combobox arrow obviously disappears, but that might not be an issue for you.

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

    Result

    Or try to change FlatStyle property to Flat so that you will see a combo box arrow:

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

    Flat