Articles in this section
Category / Section

How to change the outermost border color of the WinForms DataGrid (SfDataGrid)?

1 min read

Change the outmost border color

SfDataGrid does not have built-in support to change the outermost border color. But this can be done by the following steps:

  1. Derive a control from System.Windows.Forms.Panel and add SfDataGrid to it.
  2. Set the Panel’s DockPadding.All to 1 and set the BackColor of Panel to the expected color.
  3. Set the BorderStyle to None for both Panel and SfDataGrid.


public Form1() 
    DataGridPanel dataGridPanel = new DataGridPanel(); 
    var data = new OrderInfoCollection(); 
    dataGridPanel.DataGrid.DataSource = data.OrdersListDetails;  
public class DataGridPanel : Panel 
    public SfDataGrid DataGrid = new SfDataGrid(); 
    public DataGridPanel() 
        : base() 
        this.DockPadding.All = 1; 
        this.BackColor = Color.Blue; 
        this.BorderStyle = BorderStyle.None; 
        this.DataGrid.Dock = DockStyle.Fill; 
        this.DataGrid.Style.BorderStyle = BorderStyle.None; 
        MethodInfo method = this.DataGrid.GetType().GetMethod("UpdateStyles", BindingFlags.NonPublic | BindingFlags.Instance); 
        method.Invoke(this.DataGrid, null); 


Public Sub New()
 Dim dataGridPanel As New DataGridPanel()
 Dim data = New OrderInfoCollection()
 dataGridPanel.DataGrid.DataSource = data.OrdersListDetails
End Sub
Public Class DataGridPanel
 Inherits Panel
 Public DataGrid As New SfDataGrid()
 Public Sub New()
  Me.DockPadding.All = 1
  Me.BackColor = Color.Blue
  Me.BorderStyle = BorderStyle.None
  Me.DataGrid.Dock = DockStyle.Fill
  Me.DataGrid.Style.BorderStyle = BorderStyle.None
  Dim method As MethodInfo = Me.DataGrid.GetType().GetMethod("UpdateStyles", BindingFlags.NonPublic Or BindingFlags.Instance)
  method.Invoke(Me.DataGrid, Nothing)
 End Sub
End Class


Changed the outmost border color of DataGrid


C# : BorderColor_CS

VB : BorderColor_VB

Did you find this information helpful?
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment