Heres a programming challenge for all you .net developers. Before reading my book, please note I've got a solution to the following, I'm just seeing if there is a better way
I've got a dropdown combobox and textbox. The combobox contains prefixes for the textbox. A user can select an item from the combobox and have it appear in front of the textbox text, removing any other prefixes from the front. Simple enough, until you start throwing in a textchanged or keypress event.
The combobox selectedindex should also update should the user trigger textchanged or keypress with text containing one of the available prefixes from the combobox. Now its not so simple :/
Updating the textbox when selectedindexchanged triggers also triggers the textchanged, which in turn triggers the selectedindexchanged event again and so forth. See what hapens? Its a continuous cycle.
I can correct this by using a class level variable, and locking down the event handlers code to only occur if its permitted.
I'd rather try another approach, such as putting an optional boolean parameter in one of the event handlers and passing a true condition when the code shouldn't be permitted to run. Problem is, I'm dealing with a combobox here, so doing that wouldn't help, because changing the index to the correct one from selectedindexchanged would just retrigger the event without the true condition of the parameter, and as far as I can see theres no way of setting the condition true for the selectedindexchanged event as I'm changing the combobox selectedindex from the textchanged event of the textbox.
Next I tried checking the sender of the selectedindexchanged event to make sure its not the textbox, but .net doesnt return the textbox though it was the textchanged event of the textbox that causes selectedindexchanged of the combo box to trigger.
Ok, now that I've confused everyone, anyone have any other approach to handling this problem?