How to prevent adding a new row in WPF DataGrid when user cancels last row edit?

Grids for WPF Forum

Posted 3 months ago by Syed Muhammad Maaz
Version: 24.1.2
Avatar

I'm using Actipro's ThemedDataGrid, which inherits from WPF's DataGrid. I'm encountering an issue where a row is added to the grid even when the user cancels the edit on the last row. The user can cancel the edit by entering edit mode and then losing focus on the data grid. This is causing several problems:

  • If the user makes the last row editable but decides not to edit, the newly added row is still displayed.
  • If the user makes the last row editable and then shifts to another cell in the same row, a new row is added to the list but not shown in the grid. The user can then delete the last row, and after that, they will not be able to add a new row anymore.
  • The new row is only added when the last row enters edit mode and the grid is refreshed after losing focus. I want the new row to be added as soon as the user starts editing any cell in the last row.

I have searched the forums for similar issues and found some related threads, but the suggestions did not help. I tried canceling the edit in the CellEditEnding event after checking if any cell was changed by the user. This cancels the edit but still adds a NewItemPlaceholder to the list, which eventually gets shown in the grid after several clicks.

If anyone has found a workaround or solution for this issue, I would greatly appreciate it.

P.S. This worked fine in WinForms where we had the CurrentCellDirtyStateChanged event, but it no longer works in WPF

Comments (1)

Posted 3 months ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

I'm sorry you're having an issue here.  If you see the same thing happening with the pure Microsoft DataGrid control (instead of our ThemedDataGrid that inherits DataGrid), then your best bet would be to post for assistance in Microsoft's WPF support mechanisms or on StackOverflow since that would be related to functionality we didn't write and don't have the source code for.

On the other hand, if you only see the issue occurring in the themes we added for their DataGrid control, meaning only when using ThemedDataGrid in place of DataGrid, please email our support address a new simple sample project that shows it happening.  Then we can debug with the exact scenario in our ThemedDataGrid code to see what's happening.  Be sure to exclude the bin/obj folders from the .zip you send so it's not spam blocked.  Thanks!


Actipro Software Support

The latest build of this product (v24.1.4) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.