# Conditional Formatting Rows

Cells and rows can be styled based on data conditions using the **ConditionalFormattingObject**. Setup the condition in the constructor for the **ConditionalFormattingObject**. The constructor parameters are:

* The name of the condition.

* A **ConditionTypes** enumeration value: Equal, NotEqual, StartsWith, EndsWith, Contains, DoesNotContain, Greater, GreaterOrEqual, Less, LessOrEqual, Between, NotBetween.

* A string for the first value used to test the condition.

* A string for the second value used to test the condition.

* An "ApplyToRow" boolean that if true allows you to format the entire row that the cell appears in.

The **ConditionalFormattingObject** also contains formatting properties for the cell, row and text alignment.

* **CellBackColor:** Sets the background color for the cell.

* **CellForeColor:** Sets the cell text font color.

* **CellFont:** Sets the cell text font.

* **RowBackColor:** Sets the background color for the entire row that the cell appears in.

* **RowForeColor:** Sets the cell text font color for the entire row that the cell appears in.

* **RowFont:** Sets the cell text font for the entire row that the cell appears in.

* **TextAlignment** is a **ContentAlignment** enumeration value that can be **TopLeft**, **TopCenter**, **TopRight**, **MiddleLeft**, **MiddleCenter**, **MiddleRight**, **BottomLeft**, **BottomCenter** and **BottomRight**.

## Conditional Formatting Rows

This example looks for the same condition as the [cell formatting example](https://www.telerik.com/products/winforms/documentation/controls/gridview/visual-elements/cells/conditional-formatting-cells). The difference is that the last parameter ("ApplyToRow") passed to the **ConditionalFormattingObject** is set to *true*, allowing the **RowBackColor** property to be recognized.

![WinForms RadGridView Conditional Formatting Rows](https://www.telerik.com/products/winforms/documentation/assets/93a955f4efa16b6122abc1d8dc41a2c0/gridview-rows-conditional-formatting-rows001.png)

```C#
ConditionalFormattingObject obj = new ConditionalFormattingObject("MyCondition", ConditionTypes.Greater, "30", "", true);
obj.CellForeColor = Color.Red;
obj.RowBackColor = Color.SkyBlue;
this.radGridView1.Columns["UnitPrice"].ConditionalFormattingObjectList.Add(obj);
```

```VB.NET
Dim obj = New ConditionalFormattingObject("MyCondition", ConditionTypes.Greater, "30", "", True)
obj.CellForeColor = Color.Red
obj.RowBackColor = Color.SkyBlue
Me.RadGridView1.Columns("Unit Price").ConditionalFormattingObjectList.Add(obj)
```

> caution The declarative nature of Conditional Formatting limits the situations in which it can be used. While the provided functionality covers most scenarios, there are situations in which you will need to use [events](https://www.telerik.com/products/winforms/documentation/controls/gridview/visual-elements/rows/formatting-rows).

**RadGridView** provides a convenient form which the end user could use to create formatting objects. You can show the form by using the header cells' context menu. To access and customize the dialog, you can use the **ConditionalFormattingFormShown** event. :

![WinForms RadGridView Condi Formatting Option](https://www.telerik.com/products/winforms/documentation/assets/43e76ddb60f435d0815d09f58fa51f78/gridview-rows-conditional-formatting-rows002.png)

![WinForms RadGridView Conditional Formatting Rules Manager](https://www.telerik.com/products/winforms/documentation/assets/8d224f32944f44f883e1ca21c74d73a1/gridview-rows-conditional-formatting-rows003.png)

## See Also

* [Adding and Inserting Rows](https://www.telerik.com/products/winforms/documentation/controls/gridview/visual-elements/rows/adding-and-inserting-rows)

* [Creating custom rows](https://www.telerik.com/products/winforms/documentation/controls/gridview/visual-elements/rows/creating-custom-rows)

* [Drag and Drop](https://www.telerik.com/products/winforms/documentation/controls/gridview/visual-elements/rows/drag-and-drop)

* [Formatting Rows](https://www.telerik.com/products/winforms/documentation/controls/gridview/visual-elements/rows/formatting-rows)

* [GridViewRowInfo](https://www.telerik.com/products/winforms/documentation/controls/gridview/visual-elements/rows/gridviewrowinfo)

* [Iterating Rows](https://www.telerik.com/products/winforms/documentation/controls/gridview/visual-elements/rows/iterating-rows)

* [New Row](https://www.telerik.com/products/winforms/documentation/controls/gridview/visual-elements/rows/new-row)

* [Painting Rows](https://www.telerik.com/products/winforms/documentation/controls/gridview/visual-elements/rows/painting-rows)
