Format Grid Cells and Rows in C# Conditionally
The cells and rows in grid can be styled according to data conditions. The Kettic GridView provides the ConditionFormatObjects to accomplish the cells formatting according to data conditions. To enable the cell formatting functionality, we need to change the value of the ApplyToRow property to True for the cell objet that we are going to format. And there is a property, ApplySelectedRows, determining whether the cells formatting properties of the object will be applied to the selected rows.
Properties of Formatting Cells under Conditions
To create custom formatting cells under conditions, we need to use ConditionFormatObjects to accomplish that. The following are the properties to format cell, row, and text alignment in grid. This is achieved through applying ConditionFormatObjects which contains values like,
How to Format Cells in C# ConditonallyRule based Formatting Objects
According to the conditions which define the formatting, the cell formatting objects can be divided to rule based and expression based. The rule based formatting objects will create custom formatting cells and rows to GirdView according to defined rules, including,
We are going through an example as following to check whether the value in the second column ProductPrice is larger than 20, and if it exceeds the 20, set the back color to white, the text color to black, and the text alignment to MiddleLeft.
Expression based Formatting Objects
According to the conditions which define the formatting, the cell formatting objects can be divided to rule based and expression based. The expression based formatting objects will create custom formatting cells and rows to GirdView according to defined expression, which refers to data from different columns and result Boolean value. We are going through an example as following to check whether the value in the second column ProductPrice is larger than 20, and change the style of the ProductName column.
Customize ConditionFormatForm in C#
The Kettic DataGridView allows end users easily create custom formatting object by using the form provided additionally. We can use the ConditionFormatFormDisplay event of Kettic DataGridView to access and customize the dialog. The following is an example to hide the invisible columns in the drop down and format the columns shown.
|
UI Controlsfor Windows Forms .NET WinForms UI Overview.NET WinForms UI Features.NET WinForms UI GuideC# WinForms UI DesignVB.NET WinForms UI DesignWinForms UI Controls WinForms Buttons UI Control WinForms Calendar UI ControlWinForms Carousel UI ControlWinForms Chart UI ControlWinForms Clock UI ControlCommandBar UI ControlWinForms Dock UI ControlDesktop Alert UI ControlDropDown List UI ControlWinForms Editor UI ControlForms and Dialogs UI ControlWinForms GridView UI ControlGridView - Get Started in C#GridView - PropertiesGridView - ColumnGridView - RowGridView - CellsCells - AccessCells - PropertyCells - IterateCells - Conditional FormatCells - Format CellsCells - Set CellsCells - Painting & DrawingCells - Custom CellsGridView - EditorsEditors - PropertyEditors - EventsEditors - Data ValidationEditors - CustomizeGridView - Context MenuGridView - Populating with DataGridView - Hierarchical GridGridView - SelectionGridView - ScrollingGridView - SortingGridView - GroupingGridView - FilteringGridView - Expression EditorInsert/ Update/ Delete RecordsGridView - View DefinitionGridView - Exporting DataStyling and AppearanceGridView - LocalizationSave and Load LayoutGridView - Print SupportWinForms ListView UI ControlWinForms Menu UI ControlWinForms ComboBox UI ControlWinForms PageView UI ControlPanels and Labels UI ControlWinForms Panorama UI ControlWinForms PDFViewer UI ControlWinForms Property Grid UI ControlWinForms Ribbon UI ControlWinForms PivotGrid UI ControlWinForms RichTextBox UI ControlWinForms Rotator UI ControlWinForms Scheduler UI ControlWinForms Shortcuts UI ControlWinForms SpellChecker UI ControlWinForms Track & Status UI ControlWinForms TreeView UI ControlWinForms Wizard UI ControlWinForms Test UI ControlWinForms Theme UI Control |