1
votes

I have a DatagridView with the Option AllowUserToAddRows = True. So my user can see the last blank line and if he inserts something there a new Row is generated.

I have some calculations to do when the user changes cell values for this i use the EndEdit Event. And I also use a Custom Contextmenu to delete rows from this Datagridview.

So now my Problem, if I Add a new Row (and Important) if I do not Change the Selected Row after creation, and then delete a Row through the Contextmenu both Rows, the newly created and the one i want to delete dissapear.

I see if i create a new Row this Row is Initial in Detached State and gets Added after i Change the selected Row.

So my Question, is there a way to create a Row and set the State to Added programmatically? There is a setAdded Method in the DataRow but I couldnĀ“t call it when the Row is detached.

I have found the MSDN Article which says I had to Add the Row to a RowCollection then the Rowstate is Added, but in my Case (and Mind) the Row is allready in a RowCollection course i Add it to the datagridview....

I hope you understand my creepy english, if you need Sourcecode to understand my meaning just ask.

Best Regads

1

1 Answers

1
votes

You could listen for the RowsAdded event and change one of the values on the new row in a handler (and change it back so the user does not notice). This should do the same as manually changing some values on your row.

If no values are changed on the new row, it's not added by default, otherwise each edit you would get a new blank row added to your collection.