How to set padding for the cells in GridDataControl?
In GridDataControl, you can use the CellMarginsInfo class to describe the Cell’s Padding, TextMargins and also BorderMargins. Using the CellMarginsInfo you can define each side of the cell’s margin individually. Margin sides that are not initialized, inherit default values from the base style. Generally the properties Left, Right, Top and Bottom are used to set the respective margin values.
Following code illustrates the usage of CellMarginsInfo to set GridDataControl Cell’s Padding, TextMargins and also BorderMargins.
XAML
<Window.Resources> <syncfusion:CellMarginsInfo x:Key="CellMargin" Bottom="0" Left="10" Right="10" Top="5" /> <syncfusion:CellMarginsInfo x:Key="CellBorderMargin" Bottom="0" Left="0" Right="10" Top="3" /> </Window.Resources> <syncfusion:GridDataControl.VisibleColumns> <syncfusion:GridDataVisibleColumn MappingName="Empmobileno"> <syncfusion:GridDataVisibleColumn.ColumnStyle> <syncfusion:GridDataColumnStyle HorizontalAlignment="Left" TextMargins="{StaticResource CellMargin}"/> </syncfusion:GridDataVisibleColumn.ColumnStyle> </syncfusion:GridDataVisibleColumn> <syncfusion:GridDataVisibleColumn MappingName="mailid"> <syncfusion:GridDataVisibleColumn.ColumnStyle> <syncfusion:GridDataColumnStyle HorizontalAlignment=" Left " Padding="{StaticResource CellMargin}"/> </syncfusion:GridDataVisibleColumn.ColumnStyle> </syncfusion:GridDataVisibleColumn> <syncfusion:GridDataVisibleColumn MappingName="Designation"> <syncfusion:GridDataVisibleColumn.ColumnStyle> <syncfusion:GridDataColumnStyle HorizontalAlignment="Right" BorderMargins="{StaticResource CellBorderMargin}"/> </syncfusion:GridDataVisibleColumn.ColumnStyle> </syncfusion:GridDataVisibleColumn> </syncfusion:GridDataControl.VisibleColumns>
Here, two CellMarginsInfo definitions (CellMargin and CellBorderMargin) are created and applied to the VisibleColumns ”Empmobileno”, “Mail ID” and “Designation” using the ColumnStyle property. GridDataColumnStyle is used to set the Padding, TextMargins and BorderMargins values. CellBorderMargin is applied for BorderMargins, and CellMargin is applied for Padding and TextMargins.
The following screenshot illustrates the output for the above code in the GridDataControl.
Here you can notice that the Cell Padding and TextMargins are applied for “Mail ID” and “Empmobileno” columns that are actually left aligned and BorderMargins applied for “Designation” column that is actually right aligned. You can also note that they vary from the cells of other VisibleColumns as padding or Margins are set for those columns where cells in other columns have default value.