Hi,
some time ago I wrote a custom GridEditor using a TextBoxControlElement with AutoComplete = Suggest.
It works fine but now i need to change the auto complete logic using Contains instead of StartsWith.
I know how to do this in a DropDownList or in a DropDownListElement but can't find a way to get this behaviour in a TextBoxControl and don't want to change the TextBoxControlElement with a DropDownListElement hiding the arrow button.
How can I have a 'contains' AutoComplete in a TextBoxControls ?
Regards
4 Answers, 1 is accepted
In order to activate "contains" autocomplete functionality in RadTextBoxControl, you can simply set the AutoCompleteMode property to AutoCompleteMode.Suggest:
this.radTextBoxControl1.AutoCompleteMode = AutoCompleteMode.Suggest;this.radTextBoxControl1.AutoCompleteDataSource = this.customersBindingSource;this.radTextBoxControl1.AutoCompleteDisplayMember = "ContactName";Please refer to the following help article which gives you additional information about the autocomplete behavior: https://docs.telerik.com/devtools/winforms/editors/textboxcontrol/autocomplete
I hope this information helps. If you need any further assistance please don't hesitate to contact me.
Regards,
Dess
Progress Telerik
Hi Dess,
thanks for your answer.
Your code is almost identical at mine, but in this way I obtain a 'StartsWith' autocomplete and not a 'Contains'.
In fact the first line of the documentation says : "The RadTextBoxControl can automatically complete the input string by comparing the prefix being entered to the prefix of all strings in the maintained source."
What I want is to compare the text entered with the strings in the data source looking for those that "contains" the input string.
With a drop down I can obtain this behaviour simply writing :
this.radDropDownList.AutoCompleteMode = AutoCompleteMode.Suggest;this.radDropDownList.AutoCompleteSuggest.SuggestMode = SuggestMode.Contains;
or replacing the AutoCompleteSuggestHelper class if I need a more complex matching criteria
this.radDropDownList.AutoCompleteSuggest = new MyOwnAutoCompleteSuggestHelper();
The TextBoxControl doesn't seem to support none of this ways, so how can I get a SuggestMode.Contais behaviour ?
Note that RadTextBoxControl and RadDropDownList have a completely different auto-complete implementation. Indeed, RadDropDownList offers different auto-complete helpers for handling the "starts with" or "contains" functionality. But they are not available in RadTextBoxControl. The previously suggested solution was not quite correct in terms of the exact requirement that you are trying to achieve. Please excuse me for that. In order to show the items that "contains" the text, you can use the following custom implementation of RadTextBoxControl:
public class CustomTextBoxControl : RadTextBoxControl{ public override string ThemeClassName { get { return typeof(RadTextBoxControl).FullName; } } protected override RadTextBoxControlElement CreateTextBoxElement() { return new CustomTextBoxControlElement(); }}public class CustomTextBoxControlElement : RadTextBoxControlElement{ protected override Type ThemeEffectiveType { get { return typeof(RadTextBoxControlElement); } } protected override RadTextBoxListElement CreateListElement() { return new CustomTextBoxListElement(); }}public class CustomTextBoxListElement : RadTextBoxListElement{ protected override bool AutoCompleteFilterOverride(RadListDataItem item) { string itemText = (item.Text ?? string.Empty).ToUpperInvariant(); return itemText.Contains(this.PatternText.ToUpperInvariant()); }}Should you have further questions please let me know.
Regards,
Dess
Progress Telerik
Hi Dess,
thanks for your help, this is exactly what I needed
