Udostępnij za pośrednictwem


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

Sometimes you will want to prevent users from entering new rows of data or deleting existing rows in your DataGridView control. New rows are entered in the special row for new records at the bottom of the control. When you disable row addition, the row for new records is not displayed. You can then make the control entirely read-only by disabling row deletion and cell editing.

The following procedure requires a Windows Application project with a form containing a DataGridView control. For information about setting up such a project, see How to: Create a Windows Application Project and How to: Add Controls to Windows Forms.

Note

The dialog boxes and menu commands you see might differ from those described in Help depending on your active settings or edition. To change your settings, choose Import and Export Settings on the Tools menu. For more information, see Visual Studio Settings.

To prevent row addition and deletion

  • Click the smart tag glyph (Smart Tag Glyph) on the upper-right corner of the DataGridView control, and then clear the Enable Adding and Enable Deleting check boxes.

    Note

    To make the control entirely read-only, clear the Enable Editing check box as well.

See Also

Tasks

How to: Create a Windows Application Project

How to: Add Controls to Windows Forms

Reference

DataGridView

DataGridView.AllowUserToAddRows