Share via


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. For more information, see How to: Make Columns Read-Only in the Windows Forms DataGridView Control Using the Designer and How to: Make Columns Read-Only in the Windows Forms DataGridView Control Using the Designer and How to: Make Columns Read-Only in the Windows Forms DataGridView Control Using the Designer and 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:

See Also

Tasks

How to: Prevent Row Addition and Deletion in the Windows Forms DataGridView Control

Reference

DataGridView

DataGridView.Columns

DataGridViewColumn.ReadOnly

Other Resources

Basic Column, Row, and Cell Features in the Windows Forms DataGridView Control