MuscleHead

Has anybody noticed that setting the BackColor on a DataGridViewComboBoxCell behaves differently on Vista than it does on XP If I set the BackColor to red on XP (say, in the CellFormatting event handler), then the cell shows up as Red, and the dropdown shows up as red too. On Vista, only the dropdown shows up as red -- a non-editing cell still has the default background color.

How can I set the background color of a DataGridViewComboBoxCell on Vista when it is not dropped down

Thanks!




Re: Windows Forms Data Controls and Databinding DataGridViewComboBoxCell BackColor in Vista

Ken Tucker

I do not believe that is possible.






Re: Windows Forms Data Controls and Databinding DataGridViewComboBoxCell BackColor in Vista

Yu Guo – MSFT

Hi, MuscleHead,

Your problem seems to related to the Visual Style of Vista, and the Visual Style in Vista is more powerful than that in XP.

and you can disable the visual style of your application to retrieve your goal.

In your Program.cs

Code Snippet

//Application.EnableVisualStyles(); //Comment this line to disable Visual Style

Application.SetCompatibleTextRenderingDefault(false);

Application.Run(new Form1());

Hope this helps,

Regards






Re: Windows Forms Data Controls and Databinding DataGridViewComboBoxCell BackColor in Vista

MuscleHead

Sweet! You're right, that did work.

Now, of course, that I means I don't get all the other cool stuff that I do like about Vista's Visual Style... Is there a way to override the visual style ONLY for what I want (i.e., DataGridView combo box background in my case )






Re: Windows Forms Data Controls and Databinding DataGridViewComboBoxCell BackColor in Vista

Yu Guo – MSFT

Hi, MuscleHead,

I found a property named FlatStyle which can help you to do this job.

First, please enable your Application.EnableVisualStyles();

Then, try the following codes for your DataGridViewComboBoxColumn

Code Snippet

DataGridViewComboBoxColumn column = new DataGridViewComboBoxColumn();

column.DefaultCellStyle.BackColor = Color.Red;

column.FlatStyle = FlatStyle.Popup; //Popup and Flat both work

column.DisplayMember = "col1";

column.ValueMember = "col1";

column.DataPropertyName = "col1";

column.DataSource = datatable;

Hope this helps,

Regards






Re: Windows Forms Data Controls and Databinding DataGridViewComboBoxCell BackColor in Vista

MuscleHead

Yup, awesome. Thanks for the help.