Formatting Cells to C# DataGridView
DataGridView C#.NET component allows users of the control easily create formatting grid data cells to GridView in Windows Forms application. This is achieved by using the FormatCell event, which is able to add formatting to grid data cells as well as new row cells. The Kettic DataGridView contains the UI virtualization, which restrict the created cell elements to the currently visible cells and will reuse the created formatting grid data cells while scrolling, filtering, and grouping, etc. To prevent the formatting being applied to other column cell elements, it is necessary to reset the left cell elements.
Format Grid Data Cells Font Color in C#
The following are the C# code that shows how to formatting cells font color to GridView data cells.
Format Grid Data Cells Background in C#
The following is an example that demonstrates how to highlight certain cells in yellow color by using the FormatCell event. This background color formatting will be based on the values of the grid data cells in the same row but different columns. The example below will highlight the values in the first column when the value in the check box column returns true. C# code fo formatting cells background as following.
Format Non-data Grid Cells in C#
When we are going to format a grid data cell which contains no data, we can use the ViewFormatCell event. The FormatCell event is only for cells containing data, however, the ViewFormatCell event is able to format all cells, including, grouping row, header cells, and none data cells.
Create Formatting Group and Header Cells in C#
The following are the example that goes through the process of changing the font of the header cells and the group cells to GridView in C#.NET projects.
Format TextAlignment and Group Rows BackColor
To align the text in the grid data cells and change the back color in the group rows to none data cells in GridView C#.NET component, we can use the C# code snippet as following.
Style Button Appearance in GridViewCommandColumn
When the buttons are the children of the grid data cells, we can access the buttons through the Children collection of the visual cells to change the appearance in the GridViewCommandColumn. In the example below, we are going through how to style the button appearance.
Format Grid Data Cells as Specified
When we need to create formatting grid data cells a specific requirement, we can achieve this following the example as below. In the following example, we are going to format the button click. There is a search box above the GridView and KetticButton. When we click the button, the KetticGridView will highlight the grid data cell which matches the text entered in the KetticTextBox.
Style Property for Grid Cells Formatting
The Kettic DataGridView control provides the GridViewCellInformation Style property for users to access to the grid cell visual properties directly, which makes it possible to change styles to grid data cells at runtime instead of using the FormatCell event or the ConditionFormatObject. Furthermore, this approach will help users to customize visual properties defined by the theme and all changes will have a greater priority than the theme.
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