简体   繁体   中英

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

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

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;

If you are having trouble with this in WPF add:

CanUserAddRows="False"

To the properties of the desired datagrid in XAML.

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:)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM