Click to See Complete Forum and Search --> : DataGridViewComboBoxColumn selection disappears


gajesh
May 17th, 2009, 07:03 AM
Hello,
I am using DataGridViewComboBoxColumn as a column of DataGridView.
I have assigned data source as a List<myObject> and i am able to see all values in dropdown.

Now, for any Key Press it always select and display first element of list and but the selected value disappear as focus is taken away from the cell.

For e.g the comboBox list contains A, B, C & D. Now user presses key 'B' then it display 'B' as expected but if user presses 'E' then it display 'A' as selected and very strangely the selection disappears as focus looses from the cell.

What should i do not to display any selected value if it not in list?

jim.rushby
July 15th, 2010, 10:55 PM
Hi, did you ever solve this problem?

I'm having a very similar issue - clicking on the text portion of a DataGridViewComboBoxColumn (which has its DataSource set) will appear toselect the first value from the set. But when the combo loses focus, the value reverts to empty; you have to actually drop down the combo and click on the value in the list for it to be really selected.

I'd be very interested to hear whether you managed to prevent the auto-select, or whether it's possible to prevent the auto-selecteded value from reverting on focus loss.

Cheers,
JimbO

jim.rushby
October 3rd, 2010, 07:56 PM
I just came back to this with a fresh head and solved it as follows ...


protected override void OnEditingControlShowing(DataGridViewEditingControlShowingEventArgs e)
{
base.OnEditingControlShowing(e);

DataGridViewComboBoxEditingControl combo = e.Control as DataGridViewComboBoxEditingControl;
if (combo != null)
{
combo.SelectedIndex = -1;
}
}