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.
AddHandler 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.

Figure 1: CellPadding applied to first and second columns
Samples: