$99 VS $1000+. UI Control for ASP.NET AJAX(contains chart and gridview).
DataGridView for Windows Forms
Create data gird view in C# with modern user interface for your Windows Forms applications
Home > WinForms UI Controls > User Manual > Conditional Format Rows in C#

Format Grid Rows Conditionally for C# DataGridView

The Kettic DataGridView .NET Component provides the support of creating formatting rows to GridView based on data conditions for C# Windows Forms applications. The data grid row of GridView component representing a record that is from the Data Source and the Kettic DataGridView Control provides the FormatObjectConditions property for users of the WinForms control to create conditional formatting data rows to the DataGridView in C#.NET Windows Forms applications.

Constructor Parameters of FormatObjectConditions

The DataGridView allows users to style and customize the appearance of the grid cells and grid rows to C# GirdView according to data conditions by using the FormatObjectConditions. To style the cells and rows in grid, we need to set the conditions in the constructor for the FormatObjectConditions and the following are the constructor parameters of the FormatObjectConditions that we can use
  • Condition names of constructor parameters for FormatObjectConditions.
  • Value of condition types, including, Greater, GreaterOrEqual, Equals, NotEqual, Less, LessOrEqual, StartsWith, EndsWith, Contains, DoesNotContain.
  • A string for the first value to test the condition for the FormatObjectConditions.
  • A string for the second value to test the condition for the FormatObjectConditions.
  • An ApplyToRow boolean used to create entire formatting row when the value is true

Formatting Properties of FormatObjectConditions

The DataGridView contains various properties for the FormatObjectConditions used to format the grid cell, grid row and text alignment to DataGridView in C# Windows Forms application, including,
  • CellBackColor, this property is used to customize the background color for the grid cell.
  • CellForeColor, this property is used to change the text font color in grid cell.
  • TextAlignment, this property is used to align the text in the grid rows. The valid value contains TopLeft, TopCenter, TopRight, MiddleLeft, MiddleCenter, MiddleRight, BottomLeft, BottomCenter and BottomRight.
  • RowBackColor, this property is used to adjust the background color for the entire grid row that the cell appears in.
  • RowForeColor, this property is used to set text font color in grid cell for the entire row that the cell appears in.

Format Grid Rows in C# under Conditions

The following is an example that shows how to look for the conditions to format data rows in grid to GridView in C# Windows Forms application. And we change the parameter of ApplyToRow that is passed to the FormatObjectConditions as true to recognize the RowBackColor property.
C# code for formatting data rows to GridView under conditions

FormatObjectConditions obj = new FormatObjectConditions("MyCondition", ConditionTypes.Greater, "30", "", true);
obj.CellForeColor = Color.Blue;
obj.RowBackColor = Color.Purple;
this.ketticGridView.Columns["UnitPrice"]. FormatObjectConditionsList.Add(obj);

UI Controlsfor Windows Forms
.NET WinForms UI Overview.NET WinForms UI Features.NET WinForms UI GuideC# WinForms UI DesignVB.NET WinForms UI Design
WinForms UI Controls