I am building a kind of autocomplete text input using a WinForms ComboBox, and I need the autocompletion behavior to change depending on the position of the caret in the string.
However, the ComboBox doesn’t seem to expose an event to catch a change in the caret position. I can catch TextUpdated when the user is typing. But when the user is navigating, I need to handle KeyDown and check if the KeyCode is Left, Right, Home or End. However the event is fired before the caret is changed, so I would need to compute the new caret position. This is extremely annoying because this requires special handling when Ctrl is pressed and possibly if there are some special accessibility settings I don’t know about.
So I was wondering if there was a better way to do that. Is there an event that is fired each time the caret changes position in the ComboBox or is there a way I can execute code after the KeyDown event is handled by the ComboBox?
You can execute the code right after KeyDown processing: