Skip to content

Latest commit

 

History

History
40 lines (29 loc) · 2.49 KB

how-to-make-columns-read-only-in-the-windows-forms-datagridview-control.md

File metadata and controls

40 lines (29 loc) · 2.49 KB
title description ms.date dev_langs helpviewer_keywords ms.assetid
Make Columns Read-Only in DataGridView Control
Learn how to make columns read-only in the Windows Form DataGridView Control to prevent users from editing cells in that column.
03/30/2017
csharp
vb
data grids [Windows Forms], read-only columns
DataGridView control [Windows Forms], read-only columns
2bb73ebb-1a55-4362-9fda-e50574c087d5

How to: Make Columns Read-Only in the Windows Forms DataGridView Control

Not all data is meant for editing. In the xref:System.Windows.Forms.DataGridView control, the column xref:System.Windows.Forms.DataGridViewColumn.ReadOnly%2A 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. Also see How to: Make Columns Read-Only in the Windows Forms DataGridView Control Using the Designer.

To make a column read-only programmatically

Compiling the Code

This example requires:

  • A xref:System.Windows.Forms.DataGridView control named dataGridView1 with a column named CompanyName.

  • References to the xref:System?displayProperty=nameWithType and xref:System.Windows.Forms?displayProperty=nameWithType assemblies.

See also