As I have a client who is demanding somewhat crowded forms with too much text displayed in their combos, I'm messing around trying to improve the behaviour of the ComboEditor when it contains text that is too long to fit in the editor.
I'm running with autocomplete on, and as soon as the user types in something that autocompletes to an item longer than the combo width, the focus shifts to the right-most part of the text and they can't see what they were typing any more. The same behaviour also happens with using the up-down keys to cycle between items in the list.
As the client has a strong preference to view the left-most part of the text, and form re-design to extend the combos is out of the question, anyone have ideas on how I might force the control to stay focused on the left part of the text?
I've had minor success with using Select(0, 0) to do this on AfterDropDown/AfterCloseUp, but this doesn't do the trick in any other events.
It's certainly possible that youare fighting the Combo here.You may have noticed that the TextBox is not actually a TextBox, it's a derived class and we do override quite a few methods on it. So it's entirely possible that the Combo is doing something after the KeyDown event fires that is negating whatever you are doing. Unfortunately, if that's the case, I don't see any way around it. Unless maybe you try calling your code via a BeginInvoke. Maybe that will cuse your code to be delayed until after the Combo has already done what it needs to do.
Thanks Mike,
The inbox control looks like it offers a few more position functions (like ScrollToCaret), but after trying lots of combinations I still can't see any visible result on screen. It almost seems like something else on the ComboEditor is overriding my action afterwards, as I can't see any indication that things like Select(), SelectionStart etc are having an effect.
I'm placing my code in the KeyDown() event handler for the Up/Down keys at the moment for testing, so I wonder whether this event runs too early to be of use? Maybe autocomplete or something else kicks in later?
I don't have any conrete ideas for you here. But it might help you to know that when the combo goes into edit mode, it display an Inbox TextBox control over itself to handle the editing. So you might want to see if it's possible to do this with a Microsoft TextBox. If so, you can do someting like combo.Controls[0] to get a reference to the TextBox control and deal with it directly. This will, of course, only work when the control is in edit mode.