)
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 draw the bottom and right border of the grid when pixel scroll is enabled?

Platform: WinForms |
Control: GridControl |
Published Date: June 8, 2017 |
Last Revised Date: May 27, 2019

By default, the grid will be scrolled pixel by pixel when VScrollPixel and HScrollPixel properties are enabled. So, the bottom border of the last row and right border of the last column will not be visible. In order to display the bottom border of last row and right border of last column, CellDrawn event can be used.

Code snippet

C#

//Event Triggering
this.gridControl1.CellDrawn += new GridDrawCellEventHandler(gridControl1_CellDrawn);
 
//Event Customization
private void gridControl1_CellDrawn(object sender, GridDrawCellEventArgs e)
{
    // Draw the bottom border.
    if (e.RowIndex == this.gridControl1.RowCount
        && this.gridControl1.VScrollPixel)
    {
        e.Graphics.DrawLine(new Pen(new SolidBrush(this.gridControl1.GridLineColor), 1.5f)
        { DashStyle = DashStyle.Solid }, e.Bounds.Left, e.Bounds.Bottom - 2, e.Bounds.Right - 1, e.Bounds.Bottom - 2);
    }
 
    //Draw the right border.
    if (e.ColIndex == this.gridControl1.ColCount
        && this.gridControl1.HScrollPixel)
    {
        e.Graphics.DrawLine(new Pen(new SolidBrush(this.gridControl1.GridLineColor), 1.5f)
        { DashStyle = DashStyle.Solid }, e.Bounds.Right - 2, e.Bounds.Top, e.Bounds.Right - 2, e.Bounds.Bottom);
    }
}

 

VB

'Event Triggering
AddHandler gridControl1.CellDrawn, AddressOf gridControl1_CellDrawn
 
'Event Customization
Private Sub gridControl1_CellDrawn(ByVal sender As Object, ByVal e As GridDrawCellEventArgs)
    ' Draw the bottom border.
    If e.RowIndex = Me.gridControl1.RowCount AndAlso Me.gridControl1.VScrollPixel Then
        e.Graphics.DrawLine(New Pen(New SolidBrush(Me.gridControl1.GridLineColor), 1.5f) With {.DashStyle = DashStyle.Solid}, e.Bounds.Left, e.Bounds.Bottom - 2, e.Bounds.Right - 1, e.Bounds.Bottom - 2)
    End If
    'Draw the right border.
    If e.ColIndex = Me.gridControl1.ColCount AndAlso Me.gridControl1.HScrollPixel Then
        e.Graphics.DrawLine(New Pen(New SolidBrush(Me.gridControl1.GridLineColor), 1.5f) With {.DashStyle = DashStyle.Solid}, e.Bounds.Right - 2, e.Bounds.Top, e.Bounds.Right - 2, e.Bounds.Bottom)
    End If
End Sub

 

Screenshot

Showing default border and new border for last column in grid

Sample links:

C#: CellBorder_CS

VB: CellBorder_VB

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