Articles in this section

How to draw the bottom and right border of the grid when pixel scrolling is enabled?


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

//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);
    }
}
'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

The Screenshots below show the Default borders and Bottom right border of the Grid

Showing default border and new border for last column in WinForms Grid


Sample Links:

C#: CellBorder_CS

VB: CellBorder_VB

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Access denied
Access denied