Can't add a new record in a DataGridView in Master Details form
- Help! Totally stuck with this problem...
I have a form bound to an entity (ClientAssessment). Each client assessment record may have multiple mental health disorders associated with it. I eager load these as part of the form's query using an Include statement and display them in a DataGridView as the "detail" section of the master/detail form. This works fine. The problem is that the user should be able to assign additional mental health orders, but the DataGridView does not display a blank row at the bottom in which to enter new data. The DataGridView's EnableUserToAddRows property is set to True. Is there something else I need to do?
Any help much appreciated.
Sol
Respuestas
Here's an update on this issue, I hope it might help anyone else experiencing this problem. I stumbled across a "solution" to this problem just by fiddling around - I don't really know why it works.
My DataGridView is bound to a navigation property of the "master" entity, so when I drag this property onto my Windows form Visual Studio adds a DataGridView and a corresponding BindingSource. The BindingSource has its AllowNew property set to True. However the DataGridView does not allow new records to be added. It turns out that if I change the AllowNew property of the BindingSource to False and then back to True again everything works fine. Interestingly, the property now appears in the property designer in bold, suggesting that this is not it's default setting.
I guess this means either that the AllowNew property defaults to True but for some reason has no effect, or that it's actually False by default but displays as True in the property designer. Either way, it sure looks like a BUG.
Cheers
Sol- Marcado como respuestaDiego B VegaMSFT, Moderadorlunes, 06 de julio de 2009 6:49
Todas las respuestas
Here's an update on this issue, I hope it might help anyone else experiencing this problem. I stumbled across a "solution" to this problem just by fiddling around - I don't really know why it works.
My DataGridView is bound to a navigation property of the "master" entity, so when I drag this property onto my Windows form Visual Studio adds a DataGridView and a corresponding BindingSource. The BindingSource has its AllowNew property set to True. However the DataGridView does not allow new records to be added. It turns out that if I change the AllowNew property of the BindingSource to False and then back to True again everything works fine. Interestingly, the property now appears in the property designer in bold, suggesting that this is not it's default setting.
I guess this means either that the AllowNew property defaults to True but for some reason has no effect, or that it's actually False by default but displays as True in the property designer. Either way, it sure looks like a BUG.
Cheers
Sol- Marcado como respuestaDiego B VegaMSFT, Moderadorlunes, 06 de julio de 2009 6:49
- Hello Sol,
Sorry you didn't get an answer on this before. I can confirm that the workaround you have found is currently the best solution. We actually found this issue in WinForms databinding a few months ago and the WinForms team has created a fix that will be included in .NET 4.0.
The difference between the bold true and the non-bold true is that the non-bold true is simply the default value that the design-time components know should be applied, but it is never actually set. A bug in BindingSource was preventing it from detecting the databinding capabilities of the binding list provided by Entity Framework at runtime, and this was causing the unexpected behavior.
Thanks,
Diego
This posting is provided "AS IS" with no warranties, and confers no rights. - Tray to set to true the bindingsource.AllowNew property in the load event of the form
Darío León

