When I fill a DataGridView with data, there is always an empty row at the bottom. How do I disable this?
3 Answers
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.
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:
myDataGridView.AllowUserToAddRows = false;

- 239,200
- 50
- 490
- 574
-
3I'm getting the gray row even with the property set that way. – B. Clay Shannon-B. Crow Raven Sep 21 '12 at 16:09
-
Then set its visibility to false if the row is empty – Pierre Oct 29 '13 at 17:30
-
1I really hate this behavior. It adds a blank entry to my `DataSource`. There's no way to tell after the user has committed a row (`UserAddedRow` only happens when the user uses that blank line) – Brandon Sep 28 '15 at 14:11
-
This option is exposed as part of the Properties in the Designer when highlighting a DataGridView. It is called "AllowUserToAddRows". – Betaminos Mar 07 '22 at 15:35
If you are having trouble with this in WPF add:
CanUserAddRows="False"
To the properties of the desired datagrid in XAML.

- 45
- 1
- 5
If CanUserAddRows="False"
yet you still get a phantom row when you scroll down.
Short answer: add 3px to the DataGridView.Height
to account for the border.
If you have set the height of the DataGridView to exactly rows * rowHeight
something fun happens.
The border adds extra height:
1px for none
!
3px for SingleFixed
(default)
This causes the bottom row to not fit completely.
Because only 99% of the bottom row is visible, it creates another row below to display the remaining 1% at the top and empty space below giving the illusion of it creating a new row.
The fix is to add the 1px or 3px to perfectly fit the rows - then it won't scroll anymore :)

- 61
- 1
- 5