This documentation is archived and is not being maintained.

DataGrid.ReadOnly Property

Gets or sets a value indicating whether the grid is in read-only mode.

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

public bool ReadOnly { get; set; }

Property Value

Type: System.Boolean
true if the grid is in read-only mode; otherwise, false. The default is false.

In read-only mode, the grid can be scrolled, nodes can be expanded or collapsed, and so on. However, no additions, edits, or deletes can take place.

The DataGridColumnStyle also has a ReadOnly property that can be set to true to prevent data from being edited, on a column-by-column basis.

The ReadOnly can be set to true if you want to prohibit the user from editing the data directly in the System.Windows.Forms.DataGrid. For example, you might want to let users to see all columns in a table, but allow them to edit specific fields only through TextBox controls on a different form.

The following code example toggles the ReadOnly property.

Private Sub ToggleReadOnly(ByVal myGrid As DataGrid)
    myGrid.ReadOnly = myGrid.ReadOnly Xor True
 End Sub

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

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