How to: Make Columns Read-Only in the Windows Forms DataGridView Control
Not all data is meant for editing. In the DataGridView control, the column ReadOnly property value determines whether users can edit cells in that column. For information about how to make the control entirely read-only, see How to: Prevent Row Addition and Deletion in the Windows Forms DataGridView Control.
There is support for this task in Visual Studio. How to: Make Columns Read-Only in the Windows Forms DataGridView Control Using the Designer
How to: Make Columns Read-Only in the Windows Forms DataGridView Control Using the Designer
How to: Make Columns Read-Only in the Windows Forms DataGridView Control Using the Designer
How to: Make Columns Read-Only in the Windows Forms DataGridView Control Using the Designer
To make a column read-only programmatically
Set the DataGridViewColumn.ReadOnly property to true.
dataGridView1.Columns("CompanyName").ReadOnly = True
dataGridView1.Columns["CompanyName"].ReadOnly = true;
Compiling the Code
This example requires:
A DataGridView control named dataGridView1 with a column named CompanyName.
References to the System and System.Windows.Forms assemblies.
See Also
Tasks
How to: Prevent Row Addition and Deletion in the Windows Forms DataGridView Control
Reference
Other Resources
Basic Column, Row, and Cell Features in the Windows Forms DataGridView Control