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.
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.
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…
I spotted two bugs:
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.
Please login first to submit.