Articles in this section
Category / Section

How to set backcolor for a cell in WinForms GridGroupingControl?

1 min read

Changing back color for a cell or row

You can change the back color of the cell or row or column by using QueryCellStyleInfo event. In GridGroupingControl, the table model is derived from the Base styles. So that it does’nt support the GridGroupingControl to set styles.

The following code example explains how to change the background color of the particular cell and row by using QueryCellStyleInfo Event.

C#

void gridGroupingControl1_QueryCellStyleInfo(object sender, GridTableCellStyleInfoEventArgs e)
{
    // Applies style for a particular cell.
    if (e.TableCellIdentity.RowIndex == 5 && e.TableCellIdentity.ColIndex==3)
    {
    // Sets back color for a particular cell.
    e.Style.BackColor = Color.Red;
    }
}
void gridGroupingControl1_QueryCellStyleInfo(object sender, GridTableCellStyleInfoEventArgs e)
{
    // Applies style for a particular Row.
    if (e.TableCellIdentity.RowIndex == 6)
    {
        e.Style.BackColor = Color.Cornsilk;
    }
}

VB

Private Sub gridGroupingControl1_QueryCellStyleInfo(ByVal sender As Object, ByVal e As GridTableCellStyleInfoEventArgs)
 ' Applies style for a particular cell.
 If e.TableCellIdentity.RowIndex = 5 AndAlso e.TableCellIdentity.ColIndex=3 Then
  ' Sets back  color for a particular cell.
  e.Style.BackColor = Color.Red
 End If
End Sub
Private Sub gridGroupingControl1_QueryCellStyleInfo(ByVal sender As Object, ByVal e As GridTableCellStyleInfoEventArgs)
 ' Applies style for a particular Row.
 If e.TableCellIdentity.RowIndex = 6 Then
  e.Style.BackColor = Color.Cornsilk
 End If
End Sub

To set back color for a particular column, you can use TableDescriptor property. Refer to the following code examples.

C#

//Applies style for a particular column.
this.gridGroupingControl1.TableDescriptor.Columns["Column3"].Appearance.AnyRecordFieldCell.BackColor = Color.LightSkyBlue;

 

VB

'Applies style for a particular column.
Private Me.gridGroupingControl1.TableDescriptor.Columns("Column3").Appearance.AnyRecordFieldCell.BackColor = Color.LightSkyBlue

 

The following screenshot displays the changing background color for a particular Row and column.

 

Show change the backcolor of grid row and cell

Samples:

C#: BackColor-C#

VB: BackColor-VB

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