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

Autocomplete with 'Contains' instead of 'Starts with' on TextBoxControl

4 Answers 850 Views
TextBoxControl
This is a migrated thread and some comments may be shown as answers.
Alessio Bulleri
Top achievements
Rank 1
Alessio Bulleri asked on 20 Sep 2018, 01:30 PM

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

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 21 Sep 2018, 06:33 AM
Hello, Alessio,  

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
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Alessio Bulleri
Top achievements
Rank 1
answered on 21 Sep 2018, 07:39 AM

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  ?

 

0
Accepted
Dess | Tech Support Engineer, Principal
Telerik team
answered on 21 Sep 2018, 09:54 AM
Hello, Alessio,  

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
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Alessio Bulleri
Top achievements
Rank 1
answered on 21 Sep 2018, 10:37 AM

Hi Dess,

thanks for your help, this is exactly what I needed

Tags
TextBoxControl
Asked by
Alessio Bulleri
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Alessio Bulleri
Top achievements
Rank 1
Share this question
or