views:

134

answers:

1

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;
A: 

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.

Bobby
It seems like a bug to me too. I am using .NET 3.5, but DataGridView is defined in the 2.0 assemblies.Well, at first I wanted to set the current cell to null, but as I encountered this bug (it would be nice, that if the null value is not intended for this property - the set operation would throw an ArgumentException, or similar one) - I tried to set it to the (0,0) cell. As this code is executed within the SelectedIndexChanged event handler of the Combobox, hosted in the DataGridVeiwComboBoxCell, so when inside this event I set the current cell to (0,0) - I get the reentrant call exception.
Hassan
I just had a look at it with Reflector, and the first line of the property is a check against Null...I'm puzzled, because the Property is not setting _anything_ if you pass null value into it...at least it shouldn't according to the reflected code.
Bobby