I have a data grid view which works very well in almost all respects. However, I have a problem that arises when I allow the addition of items to the grid on the fly. I do this by intercepting the OnEditingControlShowing handler and setting the DropDownStyle to ComobBoxStyle.DropDown:
protected override void OnEditingControlShowing(DataGridViewEditingControl ShowingEventArgs e)
{
cb = e.Control as ComboBox;
if (cb != null)
{
cb.DropDownStyle = ComboBoxStyle.DropDown;
}
base.OnEditingControlShowing(e);
}
This all works perfectly, except that if a users starts typing in a combox column in the grids the value is selected and displayed, and if the value is not present in the list all the add methodolgoy works perfectly too, but when they user leaves the editing control the value is not displayed in the grid. As a result of this other validation fails since it is expecting a value at that point since the content has passed validation.
If the user then goes back and selects the same value again, it is retained correctly.
This only happens the first time that they access the grid - once data has successfully been entered into any combo in the grid it can be successfully entered in any other combo without issue until the form is closed and re-opened.
If the combo style is DropDownList it works perfectly, but we then have no option to add to the list which is a requirement.
Just to be clear about exactly what I am doing in all my test cases the grid values are not data bound, but the combo values are bound to a DataTable.
Anyone got any ideas?
Chris Bray