By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,286 Members | 2,364 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,286 IT Pros & Developers. It's quick & easy.

How can I force a change in DataGridView ComboBox column to be written to the grid?

P: 1
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;



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
May 1 '10 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.