This is a migrated thread and some comments may be shown as answers.

Preventing automatic text change on selection

1 Answer 115 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Daniel
Top achievements
Rank 1
Daniel asked on 09 May 2016, 03:15 PM
We are currently migrating a legacy system to .NET and part of my task is to design a UI framework that is able to integrate into our existing structure with as little friction as possible. For this purpose, I have written small wrapper controls that offer the interface we need, internally use Telerik controls, and translate as necessary between both.

One of the requirements is that, after selecting a dropdown item, the ComboBox itself does not decide which data to display in its TextBox. Rather, a different object will be informed about which index was selected and will set the desired text for the RadComboBox (and may also do various other things, dependent on the ComboBox and the selected index). As things currently are, the RadComboBox will automatically fill its TextBox with the result of a .ToString() of the selected dropdown item/business object. Almost immediately afterwards, our "deciding" object will overwrite the text with the desired value. This produces an unwanted flickering.

I did not find any way of telling an editable RadComboBox to stop setting its own text. I have tried setting the TextSearch.TextPath Property to an invalid value, which kind of looks better (it sets an empty string as the text, which looks more like a delay than flickering), but it triggers an ArgumentException (that is automatically swallowed), which is ugly, and comes with a noticeable delay. I have also tried handling various events (such as SelectionChanged, or the routed TextBoxBase.TextChanged Event) and setting the Handled Property of the EventArgs when we want to stop this event - but that was consequently ignored by the RadComboBox.

A similar problem was the automatic overwriting of the TextBox text when navigating the dropdown with the keyboard; Setting the CanKeyboardNavigationSelectItems property to false was the solution to that. Is a similar solution available to the problem described above, or is the setting-text-to-TextBox-on-selection baked in so much that it would be better for us to look for alternative ideas?

1 Answer, 1 is accepted

Sort by
0
Nasko
Telerik team
answered on 11 May 2016, 02:15 PM
Hi Daniel,

Thank you for sending the detailed description of the case.

The described behavior of RadComboBox and the Text property is an expected one. We are using the Text property internally in our code when the ComboBox is Editable - the Text is of great importance for the selection of the item. Basically, if the Text property of the control gets changed after a selection is made the selection will be cleared - that will affect some of the other functionalities of the control. Because of that we do not recommend changing the Text of the control after a selection is performed.

Could you please provide us some more information about your scenario - why exactly do you need to change the Text of ComboBox after a selection? Are you using some of the other functionalities of the control - a code-snippet with the Xaml of RadComboBox will also be helpful so, we could thing of an approach that will suit your requirements?

We are looking forward to hearing from you.

Regards,
Nasko
Telerik
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Tags
ComboBox
Asked by
Daniel
Top achievements
Rank 1
Answers by
Nasko
Telerik team
Share this question
or