简体   繁体   中英

.NET Unbound DataGridView AllowUsersToAddRows problem

I have an unbound DataGridView, which fill manually with DataGridViewRows. AllowUserToAddRows is set to false and everything works as expected - no NewRow is shown in the botomn of the grid.

In one method I add some more rows, edit some rows and remove some others. These manipulations work fine, BUT after these manipulations the NewRow becomes visible. NewRowindex property changes from -1 to a value, indicating it's actual index, but the AllowUsersToAddRows property stays false. This happens somewhere behind the scenes, as nowhere in my code, as far as I could see while debugging, the NewRowIndex does not change from -1 to a bigger value.

Does anyone has any clue about what could be wrong here, or maybe some detail, that i might be missing?

Later I'll try to reproduce this behavior in a simpler project and paste some code here.

EDIT: Ok, so trying to reproduce the bug in a simpler project, I noticed, that this occurs only if after all the adding/editing/removing I set the:

dgMap.CurrentCell = null;

This sounds like a bug within the Framework...which version are you using?

Also, may I suggest to always set the CurrentCell Property to a valid valid (like dgMap.CurrentCell = dgMap.Rows(0).Cells(0); )? It can save you some trouble if you try to access the selected cells.

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