Articles in this section
Category / Section

How is cell padding achieved in the WinForms GridGroupingControl?

1 min read

Cell padding

To apply Cell Padding, you have to set the Left and Right properties of the TextMargins in the Grid PrepareViewStyleInfo/QueryCellStyleInfo event handler.


//Event triggered to apply CellPadding.
this.gridGroupingControl1.TableControlPrepareViewStyleInfo += gridGroupingControl1_TableControlPrepareViewStyleInfo;
void gridGroupingControl1_TableControlPrepareViewStyleInfo(object sender, GridTableControlPrepareViewStyleInfoEventArgs e)
   if (e.Inner.ColIndex == 2 && e.Inner.RowIndex == 4)
      e.Inner.Style.TextMargins.Left =25;
   if (e.Inner.ColIndex == 1 && e.Inner.RowIndex == 5)
      e.Inner.Style.TextMargins.Right = 20;


'Event triggered to apply CellPadding.
Private Me.gridGroupingControl1.TableControlPrepareViewStyleInfo += AddressOf gridGroupingControl1_TableControlPrepareViewStyleInfo
Private Sub gridGroupingControl1_TableControlPrepareViewStyleInfo(ByVal sender As Object, ByVal e As GridTableControlPrepareViewStyleInfoEventArgs)
   If e.Inner.ColIndex = 2 AndAlso e.Inner.RowIndex = 4 Then
      e.Inner.Style.TextMargins.Left =25
   End If
   If e.Inner.ColIndex = 1 AndAlso e.Inner.RowIndex = 5 Then
      e.Inner.Style.TextMargins.Right = 20
   End If
End Sub


The following screenshot displays cell padding.

Show cell padding applied to first and second columns

Figure 1: CellPadding applied to first and second columns


C#: CellPaddingSample-C#

VB: CellPaddingSample-VB

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