Editable DataGridView behaviour

Editable DataGridView behaviour

Old forum URL: forums.lhotka.net/forums/t/7388.aspx


Michael posted on Sunday, August 02, 2009

Hi everyone

I have a BLB of BB's. The BB's simply have an Id and a required Name property. I want to add and edit the BB's in a grid, so I create a BindingSource, set AllowNew = true, create a grid, and set EnableAdding = true and EnableEditing = true. The grid now shows an asterisk on the new row. The screen's Apply button is enabled only when the BLB IsValid and IsDirty.

This arrangement allows easy adding (type type type, Enter, type type, Enter etc). The thing is, when the last value is typed, and Enter is hit, the new row is highlighted which adds a new row to the collection, and because it does not have a Name value, the collection is not valid and not saveable, and the Apply button is grayed out. I have found this confuses my clients, as they can't work out how to Save, especially when there is no default value for Name. It's not obvious that you have to select a different row to discard the new row, and make the BLB valid again. I have experimented with a default value, and found it even more confusing. When the new row is highlighted there's no error icon to show that Name is required. But, calling bindingSource.AddNew() does show the error icon straight away.

Using a default value for Name will make the collection valid, but what makes it confusing is that even though the collection count goes up with the new row selected, it is not saved unless it has been edited.

Has anyone else tried this? I'm just looking for something that is intuitive to use, without any quirky behaviour.

Regards
Michael

JonnyBee replied on Monday, August 03, 2009

Hi Michael,

I never use the DataGridViews add new or delete functions. Instead I use the BindingSourceNavigator to allow users to Add/Delete rows explicitly in the BindingSource.

To me -  that is more intuitive for the user for just the same reasons as you have experienced.

/jonnybee

tiago replied on Monday, August 03, 2009

This is a problem but it can be solved. Have a look at the sample http://www.codeproject.com/KB/cs/CslaERLB1.aspx

Copyright (c) Marimer LLC