Category / Section
How to change the GridCell's border margins, styles and appearance in WinForms GridControl?
Appearance
The WinForms GridControl supports the Borders property to change the appearance of the grid cell's border. You can configure each border side of the cell individually with a GridBorder value. A border margins property is present to control the margins on all four sides.
Using GridModel
//Borders and styles on all four sides of the cell
this.gridControl1.RowStyles[1].Borders.All = new GridBorder(GridBorderStyle.Dashed, Color.Red, GridBorderWeight.ExtraExtraThick);
//Borders and styles on the anyone of the side in the cell
this.gridControl1.RowStyles[2].Borders.Bottom = new GridBorder(GridBorderStyle.DashDotDot, Color.Pink, GridBorderWeight.ExtraThick);
this.gridControl1.RowStyles[4].Borders.Top = new GridBorder(GridBorderStyle.DashDot, Color.Purple, GridBorderWeight.ExtraExtraThick);
this.gridControl1.RowStyles[3].Borders.Right = new GridBorder(GridBorderStyle.Dotted, Color.Gold, GridBorderWeight.ExtraExtraThick);
this.gridControl1.RowStyles[5].Borders.Left = new GridBorder(GridBorderStyle.Solid, Color.Yellow, GridBorderWeight.Thick);
//BorderMargin on the cell
this.gridControl1.RowStyles[1].BorderMargins.Right = 20;
this.gridControl1.RowStyles[2].BorderMargins.Left = 22;
this.gridControl1.RowStyles[3].BorderMargins.Top = 24;
this.gridControl1.RowStyles[4].BorderMargins.Bottom = 21;'Borders on all four sides of the cell
Me.gridControl1.RowStyles(1).Borders.All = New GridBorder(GridBorderStyle.Dashed, Color.Red, GridBorderWeight.ExtraExtraThick)
'Borders on the anyone of the side in the cell
Me.gridControl1.RowStyles(2).Borders.Bottom = New GridBorder(GridBorderStyle.DashDotDot, Color.Pink, GridBorderWeight.ExtraThick)
Me.gridControl1.RowStyles(4).Borders.Top = New GridBorder(GridBorderStyle.DashDot, Color.Purple, GridBorderWeight.ExtraExtraThick)
Me.gridControl1.RowStyles(3).Borders.Right = New GridBorder(GridBorderStyle.Dotted, Color.Gold, GridBorderWeight.ExtraExtraThick)
Me.gridControl1.RowStyles(5).Borders.Left = New GridBorder(GridBorderStyle.Solid, Color.Yellow, GridBorderWeight.Thick)
'BorderMargin on the cell
Me.gridControl1.RowStyles(1).BorderMargins.Right = 20
Me.gridControl1.RowStyles(2).BorderMargins.Left = 22
Me.gridControl1.RowStyles(3).BorderMargins.Top = 24
Me.gridControl1.RowStyles(4).BorderMargins.Bottom = 21Using QueryCellInfo Event
void gridControl1_QueryCellInfo(object sender, GridQueryCellInfoEventArgs e)
{
if (e.ColIndex > 0)
{
if (e.RowIndex == 1)
{
// Borders and styles on all four sides of the cell
e.Style.Borders.All = new GridBorder(
GridBorderStyle.Dashed, Color.Red, GridBorderWeight.ExtraExtraThick);
e.Style.BorderMargins.Right = 20;
}
else if (e.RowIndex == 2)
{
// Border and style on one side of the cell
e.Style.Borders.Bottom = new GridBorder(
GridBorderStyle.DashDotDot, Color.Pink, GridBorderWeight.ExtraThick);
e.Style.BorderMargins.Left = 22;
}
else if (e.RowIndex == 3)
{
e.Style.Borders.Right = new GridBorder(
GridBorderStyle.Dotted, Color.Gold, GridBorderWeight.ExtraExtraThick);
e.Style.BorderMargins.Top = 24;
}
else if (e.RowIndex == 4)
{
e.Style.Borders.Top = new GridBorder(
GridBorderStyle.DashDot, Color.Purple, GridBorderWeight.ExtraExtraThick);
e.Style.BorderMargins.Bottom = 21;
}
else if (e.RowIndex == 5)
{
e.Style.Borders.Left = new GridBorder(
GridBorderStyle.Solid, Color.Yellow, GridBorderWeight.Thick);
}
}
}Private Sub gridControl1_QueryCellInfo(ByVal sender As Object, ByVal e As GridQueryCellInfoEventArgs)
If e.ColIndex > 0 Then
If e.RowIndex = 1 Then
'Borders on all four sides of the cell
e.Style.Borders.All = New GridBorder(GridBorderStyle.Dashed, Color.Red, GridBorderWeight.ExtraExtraThick)
e.Style.BorderMargins.Right = 20
'Borders on the anyone of the side in the cell
ElseIf e.RowIndex = 2 Then
e.Style.Borders.Bottom = New GridBorder(GridBorderStyle.DashDotDot, Color.Pink, GridBorderWeight.ExtraThick)
e.Style.BorderMargins.Left = 22
ElseIf e.RowIndex = 3 Then
e.Style.Borders.Right = New GridBorder(GridBorderStyle.Dotted, Color.Gold, GridBorderWeight.ExtraExtraThick)
e.Style.BorderMargins.Top = 24
ElseIf e.RowIndex = 4 Then
e.Style.Borders.Top = New GridBorder(GridBorderStyle.DashDot, Color.Purple, GridBorderWeight.ExtraExtraThick)
e.Style.BorderMargins.Bottom = 21
ElseIf e.RowIndex = 5 Then
e.Style.Borders.Left = New GridBorder(GridBorderStyle.Solid, Color.Yellow, GridBorderWeight.Thick)
End If
End If
End SubAfter
applying the properties, the border of the cell is displayed as follows.

Figure 1: Changing the appearance of the border of the cell.
Samples: