DataGridView.BorderStyle Property

Note: This property is new in the .NET Framework version 2.0.

Gets or sets the border style for the DataGridView.

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in

public BorderStyle BorderStyle { get; set; }
/** @property */
public BorderStyle get_BorderStyle ()

/** @property */
public void set_BorderStyle (BorderStyle value)

public function get BorderStyle () : BorderStyle

public function set BorderStyle (value : BorderStyle)

Property Value

One of the BorderStyle values. The default is FixedSingle.

Exception typeCondition


The specified value when setting this property is not a valid BorderStyle value.

This property affects the outer border of the DataGridView. To set the style of the cell borders, use the CellBorderStyle property.

The following code example demonstrates how to initialize a simple data-bound DataGridView. It also demonstrates how to set the BorderStyle property. To run this example, paste the following code into a form that contains a DataGridView named dataGridView1, replace the value of the connectionString variable specified in the code with a string that is valid for the system the example will run on, and call the InitializeDataGridView method from the form's constructor or Load event handler.

private void InitializeDataGridView()
        // Set up the DataGridView.
        dataGridView1.Dock = DockStyle.Fill;

        // Automatically generate the DataGridView columns.
        dataGridView1.AutoGenerateColumns = true;

        // Set up the data source.
        bindingSource1.DataSource = GetData("Select * From Products");
        dataGridView1.DataSource = bindingSource1;

        // Automatically resize the visible rows.
        dataGridView1.AutoSizeRowsMode =

        // Set the DataGridView control's border.
        dataGridView1.BorderStyle = BorderStyle.Fixed3D;

        // Put the cells in edit mode when user enters them.
        dataGridView1.EditMode = DataGridViewEditMode.EditOnEnter;
    catch (SqlException)
        MessageBox.Show("To run this sample replace connection.ConnectionString" +
            " with a valid connection string to a Northwind" +
            " database accessible to your system.", "ERROR",
            MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

private static DataTable GetData(string sqlCommand)
    string connectionString = "Integrated Security=SSPI;" +
        "Persist Security Info=False;" +
        "Initial Catalog=Northwind;Data Source=localhost";

    SqlConnection northwindConnection = new SqlConnection(connectionString);

    SqlCommand command = new SqlCommand(sqlCommand, northwindConnection);
    SqlDataAdapter adapter = new SqlDataAdapter();
    adapter.SelectCommand = command;

    DataTable table = new DataTable();
    table.Locale = System.Globalization.CultureInfo.InvariantCulture;

    return table;

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0

Community Additions