Click here to Skip to main content
15,886,026 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I am working on a VB.Net Windows Forms application. I added a ComboBox to my form, set its "DropDownStyle" proprty to DropDownList and added a few items in it. Now, when I am running the application and changing the combo box value with the mouse, everything is working fine and TextChanged event is firing. But if I am changing its values using up/down arrow keys, the TextChanged event is not firing.

Can anybody explain why?

Regards,
Shishir Wahi

What I have tried:

If I change the "DropDownStyle" proprty to DropDown then the issue is gone, but I have to use DropDownList style only.
Posted
Updated 21-May-23 0:47am
Comments
OriginalGriff 21-May-23 6:56am    
Solution updated.

1 solution

Because the change doesn't happen until the drop down element closes - which indicates that the user is happy with his selection, just as a click with the mouse does.

At that point, you get the event - but not before.

You do however get the SelectedIndexChanged even while the arrow keys are being pressed.
 
Share this answer
 
v2
Comments
shishirwahi 21-May-23 7:01am    
That's the issue. The event isn't firing even after the ComboBox loses focus. The "SelectedValueChanged" event is raised, "SelectedIndexChanged" is getting raised but NOT "TextChanged".
OriginalGriff 21-May-23 7:16am    
See the revised solution.
shishirwahi 21-May-23 7:28am    
Yes, I already mentioned in my comment that the SelectedIndexChanged event is getting raised, but the "Text" property is bound to a field of my database table and if the TextChanged event is not raised, the underlying dataset will not get updated. So, can you please suggest any other property that can be used for data binding instead of "Text"?
OriginalGriff 21-May-23 7:43am    
There isn't one - it's by design, as the user in in control of what happens, and his decision isn't "final" until the dropdown portion of the control closes.
And it's probably a bad idea to update databases directly while the user is making his mind up and trying to find the option he wants. That normally happens when the user is ready and signals so by making a positive action like clicking the "Save" or "OK" button. That way, they can "undo" the changes by cancelling the update.
shishirwahi 21-May-23 7:52am    
No, the database is not getting updated on textchanged event, just the dataset. There is a "Save" and "Revert" button on the form that the user presses to save or cancel the updates.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900