如何从DataGridView控件的底部删除空行?

时间:2022-08-26 21:34:48

When I fill a DataGridView with data, there is always an empty row at the bottom. How do I disable this?

当我用数据填充DataGridView时,底部总是有一个空行。如何禁用此功能?

2 个解决方案

#1


89  

Yes, there will always be an empty row at the bottom of a DataGridView. It allows the user to add new data at run-time; all they have to do is start typing in the new row.

是的,DataGridView底部总会有一个空行。它允许用户在运行时添加新数据;他们所要做的就是开始输入新行。

To disable it, you will also need to prevent the user from adding new rows. Do this by setting the AllowUserToAddRows property of your DataGridView control to False:

要禁用它,您还需要阻止用户添加新行。通过将DataGridView控件的AllowUserToAddRows属性设置为False来执行此操作:

myDataGridView.AllowUserToAddRows = false;

#2


0  

You could use RemoveAt too. As you know RemoveAt uses with index number.

你也可以使用RemoveAt。如您所知,RemoveAt使用索引号。

// Your last row index number - 1
dataGridView1.Rows.RemoveAt(18);

#1


89  

Yes, there will always be an empty row at the bottom of a DataGridView. It allows the user to add new data at run-time; all they have to do is start typing in the new row.

是的,DataGridView底部总会有一个空行。它允许用户在运行时添加新数据;他们所要做的就是开始输入新行。

To disable it, you will also need to prevent the user from adding new rows. Do this by setting the AllowUserToAddRows property of your DataGridView control to False:

要禁用它,您还需要阻止用户添加新行。通过将DataGridView控件的AllowUserToAddRows属性设置为False来执行此操作:

myDataGridView.AllowUserToAddRows = false;

#2


0  

You could use RemoveAt too. As you know RemoveAt uses with index number.

你也可以使用RemoveAt。如您所知,RemoveAt使用索引号。

// Your last row index number - 1
dataGridView1.Rows.RemoveAt(18);