Export (0) Print
Expand All

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.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Show:
© 2015 Microsoft