DataGridViewComboxColumn Background changed to color Black !

Hi,
I've a added a datagridviewComboxColumn to my grid that has datasource set to a list.
The problem that I'm encountering is when I've selected and item from the combox and then move to a different row and select a different item from that row combobox.

A solid black colour border around the cell and when you clicked on the combox dropdown button the background colour is back. What am I doing wrong?

Can someone help please .

Your help would be much appreciated.

Many thanks

[512 byte] By [YL99] at [2007-12-24]
# 1

Check the DefaultCellStyle property in the properties window of your datagridview. You can set colors there but I believe the default is blue, so you must of changed it. If that is the problem.

Another thing to check, is the columns property of your datagridview. Click on your comboboxcolumn, and I am not sure what you have, but I have Display Style = DropDownButton, the defaultcellstyle should be set to the DataGridViewCellStyle considering it is what you want.

hope that helps

ryan031581 at 2007-10-8 > top of Msdn Tech,Visual C#,Visual C# General...
# 2
I've tried what you suggested, but the result is still the same.

This is what I've done >>

//setting the datagrid

private void SetDataGridServer()
{
dataGrdServer.AutoGenerateColumns = false;
dataGrdServer.VirtualMode = true;
dataGrdServer.DataSource = _svrs;

AddDataGridServerColumns();

dataGrdServer.RowHeadersVisible = false;
dataGrdServer.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
dataGrdServer.SelectionMode = DataGridViewSelectionMode.FullRowSelect;

DataGridViewCellStyle style = new DataGridViewCellStyle();
style.BackColor = Color.Cornsilk;
style.ForeColor = Color.Brown;

dataGrdServer.AlternatingRowsDefaultCellStyle = style;
dataGrdServer.Columns[1].CellTemplate.Style = dataGrdServer.DefaultCellStyle;
dataGrdServer.BackgroundColor = Color.Beige;
}

//Add the combox Column
private void AddComboxColumn()
{
DataGridViewComboBoxColumn cboColum = new DataGridViewComboBoxColumn();
{
cboColum.DataSource = Enum.GetValues(typeof(EApplicationState));
cboColum.DataPropertyName = "State";
cboColum.HeaderText = "State";
cboColum.MaxDropDownItems = 4;
cboColum.FlatStyle = FlatStyle.Flat;
cboColum.DisplayStyle = DataGridViewComboBoxDisplayStyle.DropDownButton;
}
dataGrdServer.Columns.Insert(1, cboColum);
}

private void dataGrdServer_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
Utils.Debug("EditingContorls",e.Control.ToString());

DataGridViewComboBoxEditingControl combo = (DataGridViewComboBoxEditingControl) e.Control;
combo.SelectedIndexChanged += new EventHandler(combo_SelectedIndexChanged);
combo.TextChanged += new EventHandler(combo_TextChanged);
}

void combo_TextChanged(object sender, EventArgs e)
{
Utils.Debug("Something Changed In TextChanged");
Utils.Debug(dataGrdServer.SelectedCells[1].Value);
}
void combo_SelectedIndexChanged(object sender, EventArgs e)
{
Utils.Debug(((DataGridViewComboBoxEditingControl) sender).SelectedValue.ToString());
}

YL99 at 2007-10-8 > top of Msdn Tech,Visual C#,Visual C# General...
# 3
I have been trying to recreate the problem in one of my projects using your code, and I can't seem to make it happen. I would reconsider setting the datagridview.backgroundcolor if you have a cell style. You are setting the alternating rows to your style, and also columns[1]. There is something interferring here. Do a little trial and error, comment out a line where you are setting styles and background colors. Sorry if this does not help any.
ryan031581 at 2007-10-8 > top of Msdn Tech,Visual C#,Visual C# General...