Skip to content

DataGridView DefaultValuesNeeded event fires for the first row when Datasource is set #498

Closed

Description

@itg-assistant

Alex Prinias asked 2016-12-19 21:12:37 UTC

Hi guys,

Please have a look at the attached project.

There are three dgvs, bound to the same datasource. They all have AllowUserToAddRow = true.

The top one, has no DefaultValuesNeeded event. The source list is displayed correctly.

The second one has DefaultValuesNeeded event, in which two column values are set. When the dgv Datasource is set, the event fires (incorrecty I suppose -- it also fires twice) for RowIndex = 0, and the list is displayed as in the first dgv, but with the two column values of the first row changed by the event.

For the third one, an empty datasource is set, but the event fires again, and instead of having an empty "add new" row, the single row shows up with the two column values set by the event.

I suspect it is a regression.

Best,
Alex

Activity

  1. itg-assistant commented on Jun 12, 2026

    @itg-assistant
    Author

    Luca answered 2016-12-19 23:58:21 UTC

    Hi Alex,

    I spotted two bugs:

    • The vertical scrollbar is incorrect: WJ-7892

    • The new row shouldn't be there even with AllowUserToAddRows = true since the source is not an IBindingList. WJ-7893.

    Changing the list to an IBindingList (BindingSource) I can see the calls to DefaultValuesNeeded but they all seem correct. I tried the same app in WinForms and the call to DefaultValuesNeeded comes every time you enter the automatic new row. Wisej by design does it differently to avoid updating all the cells when the automatic new row is entered and left, so it calls DefaultValuesNeeded when the automatic new row is created (once).

    However, during the creation of the DGV, or assigning the data source, changing the column collection, the automatic new row may get removed and added several times as the table model changes. For example, the when the grid is created, the automatic new row is created (DefaultValuesNeeded is called), when the datasource is assigned all the existing rows are removed, the new rows from the data source are added, and then the automatic new row is created again (DefaultValuesNeeded is called again).

    In fact with the test app, if you edit the new row in the first grid (the one without  DefaultValuesNeeded) you get a data error from the combobox column since it cannot convert "" to the index in the Profession list. The other 2 grids instead have the new row initialized correctly.

    Best,

    Luca

  2. added
    BugSomething is broken or behaving unexpectedly.
    on Jun 12, 2026
  3. itg-assistant commented on Jun 12, 2026

    @itg-assistant
    Author

    Alex Prinias answered 2016-12-20 00:12:39 UTC

    Hi Luca,

    Can you mail me the modified project (with the IBindingList - BindingSource)? I just changed the DataSource seetings to = new BindingSource(persons, null) and I keep getting errors in all grids (conversion of the string '' to Int32). Additionally, I keep seeing the incorrect modification of the first row in the middle grid. So, please send me the modified project, I might be missing something very basic...

    Thanks,
    Alex

  4. itg-assistant commented on Jun 12, 2026

    @itg-assistant
    Author

    Luca answered 2016-12-20 16:55:03 UTC

    Hi Alex,

    I have missed something very basic: the description of the problem and the labels in the sample. :) I didn't see that the main issue was that the row index was zero for a grid with more rows. The bug is logged as WJ-7894: DGV may fire DefaultValusNeeded with row index = 0 when binding to list instead of the index of the automatic new row.

    The rest of my long answer is still valid.

    Best,

    Luca

  5. itg-assistant commented on Jun 12, 2026

    @itg-assistant
    Author

    Alex Prinias answered 2016-12-20 17:10:15 UTC

    yeah, the description and the labels were quite essential :)

    If you don’t see any errors during editing the new row, I’d be very interested to see what modifications you have made compared to my original project… I keep getting errors.
    A

  6. itg-assistant commented on Jun 12, 2026

    @itg-assistant
    Author

    Luca answered 2016-12-20 17:28:50 UTC

    I’ll send the changes and the dev build.

  7. itg-assistant commented on Jun 12, 2026

    @itg-assistant
    Author

    Frank (ITG) answered 2016-12-21 18:07:19 UTC

    Hi Alex,

    fix for WJ-7894 is included in the latest build (1.3.18).

    Best regards
    Frank

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

    BugSomething is broken or behaving unexpectedly.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions