Hi,
I have to implement a specific user control based on an UltraComboEditor.
This control must provides a classic combo box with a list of choices, and a button to display an external editor to enter a custom value.
That's why, I have to configure the combo box as DropDown. But in the same time, I want to prevent the text edition capabilities of the combo box.
I can't switch to a DropDownList combo box style, because in this case I'll not be able to handle custom value coming from the external editor.
I tried to disable edit with the BeforeEnterInEditMode event (e.Cancel = true), but it also disable the drop down an button click capabilities.
Is there a way to disable just the edit part of a DropDown combo box ?
We have the same behavior to implement in a grid and in this case we use the NoEdit constants on the cell activation property. Maybe there is something similar in classic controls ?
Best regards.
Jean-Charles Durand
Jean-Charles Durand said:I can't switch to a DropDownList combo box style, because in this case I'll not be able to handle custom value coming from the external editor.
Using DropDownList style would be the best way I can think of. Why isn't this an option for you? My guess is that you can assign a custom value to the control's Value property since the control will not accept anything that does not exist on the list. Is that why? If so, then one solution would be to add the custom value to the list first.
If that's not an option, then I don't think there's any easy way to do this. You could try trapping KeyDown and cancelling it, but that would be tricky, because there are some keys you probably would want to work, like the up and down arrows keys and F2.
Hi Mike,
In our case, we don't want to add custom values coming from the external editor to the combo box value list.
Combo box values are just here as predefined values.
There is no way to display a value in the combo box which is not present in the value list property ?
Best regards,
Jean-Charles Durand said:There is no way to display a value in the combo box which is not present in the value list property ?
No, not in DropDownList mode. That's one of the requirements of DropDownList - the current value of the control cannot be a value that does not exist on the list.
So that means you are pretty much limited to DropDown style. And the only way to prevent typing in that case is to handle the keystrokes, which is not a trivial undertaking.
Maybe you could consider taking another approach. You could let the users type into the combo and then validate what they typed when they try to leave the control. This would be pretty simple - you just use the IsItemInList method (in the Validating event) to determine if what they typed it on the list. If not, you could prompt them to confirm that they meant to type in a custom value and if not, cancel the event.
After reading and studying your proposal, I found a solution to create my control.
It was done in two steps:
- First, when a custom value come from my external editor, TextChanged event of the combo box is unsubscribe while the data is applied to the model.
- Then, when TextChanged event is fired, we check if the new value is present in the combo box value list. If not, it means that the value has been entered by the user. So in this case the value from the model is reassign.
It works perfectly with no blinking effect.
Thanks for the support.