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 to change the outermost border color of the WinForms DataGrid (SfDataGrid)?

Platform: WinForms |
Control: SfDataGrid |
Published Date: August 31, 2018 |
Last Revised Date: January 13, 2020
Tags: styling

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.

C#

public Form1() 
{ 
    InitializeComponent(); 
 
    DataGridPanel dataGridPanel = new DataGridPanel(); 
    this.Controls.Add(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); 
        this.Controls.Add(this.DataGrid); 
    } 
} 

VB

Public Sub New()
 InitializeComponent()
 
 Dim dataGridPanel As New DataGridPanel()
 Me.Controls.Add(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()
  MyBase.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)
  Me.Controls.Add(Me.DataGrid)
 End Sub
End Class

 

Changed the outmost border color of DataGrid

Samples:

C# : BorderColor_CS

VB : BorderColor_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