How to disable creation of new rows in a DataGridV

2020-08-09 10:12发布

问题:

This is about a .NET Windows Forms application written in C#. I have a DataGridView which is connected to a database. It displays the contents of a selected table.

Now if there are 4 rows in that table, it will display 4 rows. After this I am able to enter the 5th row in the datagrid view. It should be avoided. Now I have to disable creation of a new row. How can I do it?

回答1:

Simply set the DataGridView.AllowUserToAddRows property to false.



回答2:

Set

dataGrid.AllowUserToAddRows = false


回答3:

In XAML, set the property CanUserAddRows to false. For example see the following code

 <DataGrid   CanUserAddRows="False">

 </DataGrid>


回答4:

Do this:

this.dataGridView1.DataBindings.Clear();
this.dataGridView1.DataSource = (set the original source back)