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. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How do I make Cell Spanning ,Cell Spacing and Cell Padding in GridDataBoundGrid?.

Platform: WinForms |
Control: GridDataBoundGrid(Classic)


Cell Spanning:

You could use the CoveredRange support to acheive Cell Spanning. Please refer this code snippet:


// Spans (2,1) and (3,1) cells---------Row Spanning


this.gridDataBoundGrid1[2,1].Text="This spans 2 rows";

//Spans (6,1) and (6,2) cells---------Column Spanning


this.gridDataBoundGrid1[6,1].Text="This spans 2 columns";


'Spans (2,1) and (3,1) cells---------Row Spanning


Me.gridDataBoundGrid1(2,1).Text="This spans 2 rows"

'Spans (6,1) and (6,2) cells---------Column Spanning


Me.gridDataBoundGrid1(6,1).Text="This spans 2 columns"

Cell Padding:

You can set the GridStyleInfo's TextMargins.Left / TextMargins.Right property. For individual cells, you have to set the properties by handling the PrepareViewStyleInfo. Please refer the following code snippet:


// Cell padding for all the cells in a column




// Cell padding for a particular cell

// Subcribe to PrepareViewStyleInfo

this.gridDataBoundGrid1.PrepareViewStyleInfo += new Syncfusion.Windows.Forms.Grid.GridPrepareViewStyleInfoEventHandler(this.gridDataBoundGrid1_PrepareViewStyleInfo);

// Event Handler

private void gridDataBoundGrid1_PrepareViewStyleInfo(object sender, Syncfusion.Windows.Forms.Grid.GridPrepareViewStyleInfoEventArgs e)


// Set the Textmargins for (1,1)

if(e.RowIndex==1 && e.ColIndex==1)




// Align the text to center





Cell padding for all the cells in a column

Me.gridDataBoundGrid1(1,4).Text="Custom Borders"




' Cell padding for a particular cell

' Subcribe to PrepareViewStyleInfo

//Event Handler

Private Sub gridDataBoundGrid1_PrepareViewStyleInfo(ByVal sender As Object, ByVal e As Syncfusion.Windows.Forms.Grid.GridPrepareViewStyleInfoEventArgs) Handles gridDataBoundGrid1.PrepareViewStyleInfo

'Set the Textmargins for (1,1)

If (e.RowIndex=1) AndAlso (e.ColIndex=1) Then



'Align the text to center


End If

End Sub

Cell Spacing:

For Cell Spacing, you need to handle the DrawCellFrameAppearance event and draw custom borders between adjacent cells. Please refer the following code snippet:


//Event Handler

private void gridDataBoundGrid1_DrawCellFrameAppearance(object sender, syncfusion.Windows.Forms.Grid.GridDrawCellBackgroundEventArgs e)


int rowIndex =e.Style.CellIdentity.RowIndex;

int colIndex = e.Style.CellIdentity.ColIndex;

if (rowIndex > 0 && colIndex > 0)


Brush brush;

Graphics g = e.Graphics;

brush = new System.Drawing.Drawing2D.LinearGradientBrush(e.TargetBounds, Color.FromArgb( 0, 0, 0 ), Color.FromArgb( 255, 250,250 ), 35f);

// Draw custom border for the cell. Space has been reserved for this

// area with the TableStyle.BorderMargins property.

Rectangle rect = e.TargetBounds;

rect.Inflate(-2, -2);

Rectangle[] rects = new Rectangle[]


new Rectangle(rect.X, rect.Y, rect.Width, 4),

new Rectangle(rect.X, rect.Y, 4, rect.Height),

new Rectangle(rect.Right-4, rect.Y, 4, rect.Height),

new Rectangle(rect.X, rect.Bottom-4, rect.Width, 4),


g.FillRectangles(brush, rects);

e.Cancel = true;




'Event Hanlder

Private Sub gridDataBoundGrid1_DrawCellFrameAppearance(ByVal sender As Object, ByVal e As Syncfusion.Windows.Forms.Grid.GridDrawCellBackgroundEventArgs) Handles gridDataBoundGrid1.DrawCellFrameAppearance

Dim rowIndex As Integer =e.Style.CellIdentity.RowIndex

Dim colIndex As Integer = e.Style.CellIdentity.ColIndex

If rowIndex > 0 AndAlso colIndex > 0 Then

Dim brush As Brush

Dim g As Graphics = e.Graphics

brush = New System.Drawing.Drawing2D.LinearGradientBrush(e.TargetBounds, Color.FromArgb(0, 0, 0), Color.FromArgb(25, 250,250), 35f)

' Draw custom border for the cell. Space has been reserved for this

' area with the TableStyle.BorderMargins property.

Dim rect As Rectangle = e.TargetBounds

rect.Inflate(-2, -2)

Dim rects As Rectangle() = New Rectangle() {New Rectangle(rect.X, rect.Y, rect.Width, 4), New Rectangle(rect.X, rect.Y, 4, rect.Height), New Rectangle(rect.Right - 4, rect.Y, 4, rect.Height), New Rectangle(rect.X, rect.Bottom - 4, rect.Width, 4)}

g.FillRectangles(brush, rects)

e.Cancel = True

End If

End Sub

Here is the link with both CS and VB samples: http://websamples.syncfusion.com/samples/KB/Grid.Windows/GDBG_Cellspan/main.htm

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
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