views:

299

answers:

1

Let's clear the situation in here. Let's have a devexpress's gridview control in a WIN form. Let's set the Appearance of the Even rows of the grid have the backcolor = color.whiteSmoke (say to help the users distiguish the rows easily). We do this in design time. Now, let's do programmatically color in red some rows that match my condition in an event: gridView_RowStyle.

The problem is than the even rows, matching my condition are still colored in whitesmoke?!?!?

Does that mean that the appearance of the even rows are overwritten to the custom appearance???

I'm not getting that. What I'm I supposed to do so that the rows that match my condition are colored in red?

+1  A: 

Well, as it was obvious, yes, the appearance of the even rows was overwritten to the appearance of the rows I colored at the RowStyle event.

The solution, so that the overwritten is avoided is the use of the DevExpress.XtraGrid.StyleFormatCondition object, while programmatically binding the grid, as in the following example:

this.gridControl.DataSource = dataTable;

DevExpress.XtraGrid.StyleFormatCondition styleFormatCondition1 = 
                new DevExpress.XtraGrid.StyleFormatCondition();

styleFormatCondition1.Appearance.BackColor = System.Drawing.Color.LightCoral;
styleFormatCondition1.Appearance.BackColor2 = System.Drawing.Color.SeaShell;
styleFormatCondition1.Appearance.Options.UseBackColor = true;
styleFormatCondition1.ApplyToRow = true;
styleFormatCondition1.Condition = DevExpress.XtraGrid.FormatConditionEnum.Equal;
styleFormatCondition1.Column = this.gridView.Columns["MY_COLUMN"];
styleFormatCondition1.Value1 = "0";

this.gridView.FormatConditions.AddRange(
                new DevExpress.XtraGrid.StyleFormatCondition[] {styleFormatCondition1});

This did solve my problem. Hope it helps somebody.