简体   繁体   English

.NET Unbound DataGridView AllowUsersToAddRows问题

[英].NET Unbound DataGridView AllowUsersToAddRows problem

I have an unbound DataGridView, which fill manually with DataGridViewRows. 我有一个未绑定的DataGridView,它会手动填充DataGridViewRows。 AllowUserToAddRows is set to false and everything works as expected - no NewRow is shown in the botomn of the grid. AllowUserToAddRows设置为false,并且一切都按预期方式工作-网格的底部未显示NewRow。

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. 这些操作工作正常,但是在这些操作之后,NewRow变为可见。 NewRowindex property changes from -1 to a value, indicating it's actual index, but the AllowUsersToAddRows property stays false. NewRowindex属性从-1更改为一个值,表示它的实际索引,但是AllowUsersToAddRows属性保持为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. 就我在调试中看到的情况而言,这发生在幕后某个地方,在我的代码中没有任何地方,NewRowIndex不会从-1更改为更大的值。

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? 这听起来像是Framework中的错误...您正在使用哪个版本?

Also, may I suggest to always set the CurrentCell Property to a valid valid (like dgMap.CurrentCell = dgMap.Rows(0).Cells(0); )? 另外,我是否建议始终将CurrentCell属性设置为有效的有效值(例如dgMap.CurrentCell = dgMap.Rows(0).Cells(0); )? It can save you some trouble if you try to access the selected cells. 如果您尝试访问选定的单元格,则可以为您省去一些麻烦。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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