Changing the backcolor in a DataGridView

flynn

Regular
Joined
Jul 28, 2005
Messages
59
I am wanting to change the backcolor of a specific row/cell in a DataGridView control using the following code:

Code:
private void CustomGridCellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
        {
            if (dgSearchResults.Columns[e.ColumnIndex].Name.Equals("column1"))
            {
                // Ensure that the value is a string.
                String stringValue = e.Value as string;
                if (stringValue == null) return;

                switch (stringValue)
                {
                    case "G":
                        e.CellStyle.BackColor = Color.Gold;
                        break;
                    case "S":
                        e.CellStyle.BackColor = Color.Silver;
                        break;
                    case "N":
                        break;
                }
            }
        }

This delegate gets called but the backcolor doesn't change. Am I missing something?

tia,
flynn
 
Back
Top