DataGridView ComboBox Strange Behaviour.

A

Andrew Burns

I will attempt to be as brief as possible while still providing the
most accurate details.

I have a DGV that is bound to a binding source (which it's self is
bound to a BO). In my DGV I have a combo column that is the part
number. I have done the EditingControlShowing and all that....

I have the part number pulling from a List<string> and the list and
auto complete works as expected. However if I am using ONLY keyboard
navigation I must type the value twice to get the DGV to push it to the
BO. Here is how it goes:

1. Enter Qty (first field)
2. Tab into part number
3. Start typing (combo box starts autocomplete as expected)
4. Tab out of field <===Value does not get pushed to BO, no matter if
only part of the PN# is typed or all of it is)
5. Shift tab (or arrow) back to part number, type again
6. Tab out of PN# <===Value is pushed to BO.

If I use the mouse to click and select a part then it works as expected
on the first shot.

I have been pulling my hair out for two days changing small things to
see if it helps and it does not. I have debugging trace statements all
over so I know that it is NOT even trying to push to the BO so I am not
sure where I can inject code to help.

Any ideas?
 
B

Bart Mermuys

Hi,

Andrew Burns said:
I will attempt to be as brief as possible while still providing the
most accurate details.

I have a DGV that is bound to a binding source (which it's self is
bound to a BO). In my DGV I have a combo column that is the part
number. I have done the EditingControlShowing and all that....

I have the part number pulling from a List<string> and the list and
auto complete works as expected. However if I am using ONLY keyboard
navigation I must type the value twice to get the DGV to push it to the
BO. Here is how it goes:

1. Enter Qty (first field)
2. Tab into part number
3. Start typing (combo box starts autocomplete as expected)
4. Tab out of field <===Value does not get pushed to BO, no matter if
only part of the PN# is typed or all of it is)
5. Shift tab (or arrow) back to part number, type again
6. Tab out of PN# <===Value is pushed to BO.

If I use the mouse to click and select a part then it works as expected
on the first shot.

I have been pulling my hair out for two days changing small things to
see if it helps and it does not. I have debugging trace statements all
over so I know that it is NOT even trying to push to the BO so I am not
sure where I can inject code to help.

I think i can reproduce it, when you type and the combobox autocompletes and
then tab to another cell, the actual item lookup happens to late, therefore
SelectedIndexChanged and NotifyDirtyCell happens to late too and commit edit
doesn't commit because isdirty wasn't true.

You could try if this helps:

// attach eventhandler to dataGridView_CellLeave
private void dataGridView_CellLeave(object sender, DataGridViewCellEventArgs
e)
{
if ( dataGridView.EditingControl is DataGridViewComboBoxEditingControl)
dataGridView.EditingPanel.Select(); // force validation on
ComboBox
}

HTH,
Greetings
 
A

Andrew Burns

Bart,
That appears to have worked!!! Thank you soo much this has been driving
me crazy for a week!!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top