)
We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to change the GridCell's border margins, styles and appearance in WinForms GridControl?

Platform: WinForms |
Control: GridControl |
Published Date: April 30, 2011 |
Last Revised Date: December 17, 2019
Tags: styling

Appearance

The 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

C#

//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;

VB

'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 = 21

Using QueryCellInfo Event

C#

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;
  }
  //Borders and styles on the anyone of the side in the cell
  else if (e.RowIndex == 2 )
  {
   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);
  }
 }
}

VB

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 Sub

After applying the properties, the border of the cell is displayed as follows.

Changing the appearance of the border of the cell

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

Samples:

C#: Cell border style

VB: Cell border style

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon