Click here to Skip to main content
15,916,091 members

Comments by AcidUser85 (Top 2 by date)

AcidUser85 19-Nov-15 3:01am View    
Hi, I forgot to mention that my solution also does automatic sort of datagridview rows by 2 columns when focus is lost or another control selected. So marking for deletion would mess up things.

It works like this:
DataGridView is in my case of two columns.
1-st column is column of comboboxes (sort of type).
2-nd column is column of textboxes (sort of text description).
A combobox has items, let's say "Custom","AAAA","BBBB","CCCC".
When user selects "Custom", then ComboBox is set to editable and user can type custom value, that will be added to ComboBox items.

I thought about making cell read-only when selected item is "Custom".
But I cannot force user to input correct value for combobox before navigating away. And since DataGridView automatically adds new blank row, it can result in multiple not correctly formatted rows.
AcidUser85 18-Nov-15 12:28pm View    
In my solution I remove rows if combobox seleted value is empty or "custom" in case if user moves to another cell or another row, another control is focused or user clicks outside of datagridview control - on to form.
That's why I cannot use cellvalidating and cellvalidated events - these event's do not allow to remove row. Also I experienced instability when using multiple events, that's why I handle everything in "DirtyStateChanged" event.
I tried assigning "SelectedIndexChanged" to combobox cell editing control, but this never worked for me.