How do I remove the empty row from the bottom of a DataGridView control?

C#.NetWinformsDatagridview

C# Problem Overview


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

C# Solutions


Solution 1 - C#

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;

Solution 2 - C#

If you are having trouble with this in WPF add:

CanUserAddRows="False"

To the properties of the desired datagrid in XAML.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionLukeView Question on Stackoverflow
Solution 1 - C#Cody GrayView Answer on Stackoverflow
Solution 2 - C#JuliaView Answer on Stackoverflow