Skip to content

DGV Add new #225

Closed
Closed

Description

@itg-assistant

Alex Prinias asked 2016-09-01 10:14:46 UTC

Hi,

Tiago, your experience here will be invaluable....

I have a DGV with AllowUserToAddRows = true and EditMode = OnEnter and saving to my db on RowLeave. I go to the last empty line, it opens up TextBox for insertion, then I regret it and move the cursor up. The RowLeave event fires and it goes on to save to the db. The problem is that DGV's Datasource has a new record with the empty values of the last DGV row and my validation fails. It seems that, although I abandoned insertion, a new record is inserted into the Datasource. If this is true, there should be two empty rows in the grid, the one with the empty values I just entered and the new "new record" row....(by the way, a "new" icon there would be very useful, like the "*" icon in old dgv's).

So, if the underlying behaviour is as I suspect, there should be two empty rows to indicate that a new (empty value row) was inserted.

The ideal would be that if nothing is inserted in the new row, there is nothing added to the Datasource.

Unless I'm missing something! :-)

Best,
Alex

Activity

  1. itg-assistant commented on Jun 12, 2026

    @itg-assistant
    Author

    Luca answered 2016-09-01 15:13:37 UTC

    Hi Alex,

    This is the general behavior when AllowUserToAddRows is true:

    • When you type in a cell in a new row (row.IsNewRow == true) and leave the cell the value is committed (only if not empty or different from what was there before in case the new row had default values) and the new row is added to the connected data source. Until then it's not in the data source. After the new row is committed (added to the data source) the grid fires OnUserAddedRow().

    • When a new automatic row is added, the grid fires OnNewRowNeeded, if VirtualMode is on, and then fires OnDefaultValuesNeeded to let the app initialize the automatic new row. You can check in the code to see if it's the automatic new row by testing row.IsNewRow.

    • If you press Escape while editing in an automatic new row, or don't change the cell value, the row is not committed, not added to the data source.

    The new row icon (+) is there already, also with the editing icon (pencil). But you probably need to update the Classic-2 theme in your app. Hopefully the themes won't change much after the release. The next two big changes in all the themes will be: ListView, PropertyGrid, and the Collapsible Nested Rows in the DGV.

    HTH

    Best,

    Luca

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    GeneralQuestions, how-tos and everything else.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions