Articles in this section
Category / Section

How to apply different styles for the specific column or row or cell in WinForms GridGroupingControl?

1 min read

Styles settings

In GridGroupingControl, specific styles for individual row, column and cells can be specified by using the QueryStyleCellInfo event. This event can be used to get or set every style properties of the grid. Any specified criteria of a row or column or cell can be applied with the style values.

C#

// form ()
// Trigger the required event
this.gridGroupingControl1.QueryCellStyleInfo += new GridTableCellStyleInfoEventHandler(gridGroupingControl1_QueryCellStyleInfo);
 
void gridGroupingControl1_QueryCellStyleInfo(object sender, GridTableCellStyleInfoEventArgs e)
{
    // Sets a specified style for a row.
    if(e.TableCellIdentity.RowIndex == 7)
    {
       e.Style.BackColor = Color.PaleGreen;
    }
    // Sets a specified style for a column.
    if(e.TableCellIdentity.ColIndex == 3)
    {
       e.Style.TextColor = Color.Red;
       e.Style.CellValueType = typeof(Int32);
    }
    // Sets a specified style for a single cell.
    if(e.TableCellIdentity.RowIndex == 6 && e.TableCellIdentity.ColIndex == 2)
    { 
       e.Style.BackColor = Color.LightPink;
       e.Style.CellType = GridCellTypeName.ProgressBar;
    }
}

VB

' form () 
' Trigger the required event
AddHandler gridGroupingControl1.QueryCellStyleInfo, AddressOf gridGroupingControl1_QueryCellStyleInfo
 
Private Sub gridGroupingControl1_QueryCellStyleInfo(ByVal sender As Object, ByVal e As GridTableCellStyleInfoEventArgs)
   ' Sets a specified style for a row.
   If e.TableCellIdentity.RowIndex = 7 Then
       e.Style.BackColor = Color.PaleGreen
   End If
   ' Sets a specified style for a column.
   If e.TableCellIdentity.ColIndex = 3 Then
       e.Style.TextColor = Color.Red
       e.Style.CellValueType = GetType(Int32)
   End If
   ' Sets a specified style for a single cell.
   If e.TableCellIdentity.RowIndex = 6 AndAlso e.TableCellIdentity.ColIndex = 2 Then
       e.Style.BackColor = Color.LightPink
       e.Style.CellType = GridCellTypeName.ProgressBar
   End If
End Sub

Screenshot

Show the different style applied to GridGroupingControl

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied