Show auto-complete items which text contains the user's input in RadTextBoxControl
Environment
| Product Version | 2018.3 911 |
| Product | RadTextBoxControl for WinForms |
Description
RadTextBoxControl supports auto-complete functionality which can automatically complete the input string by comparing the prefix being entered to the prefix of all strings in the maintained source. You just should set the AutoCompleteMode property to the desired mode.However, a common scenario is to show not only the items which text starts with the specified input but to display these ones that contain the text. This article shows how to complete the items that contain the entered text.
Default Starts With Auto-complete functionality

Solution
It is necessary to override the default auto-complete logic in the AutoCompleteFilterOverride method of the RadTextBoxListElement that is hosted in the RadTextBoxControlElement and change it to search for items that contain the pattern. This can be achieved by creating a derivative of the RadTextBoxControl which custom implementation is demonstrated below:
"Contains" Auto-complete functionality

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());
}
}