Is it possible to use unicode characters like ç or ï and still get a match with c or i with autocomplete in the combobox
like string.Compare("CZSczs", "ČŽŠčžš", CultureInfo.InvariantCulture, CompareOptions.IgnoreNonSpace);
so if a type czczs i get a match with CZSczs and with ČŽŠčžš in the autocomplete list
ComboBoxEdit - How to search with unicode characters and user defined comparison
Answers approved by DevExpress Support
Hi,
At present, ComboBoxEdit supports only case-sensitive and case-insensitive search. To support the required functionality, it is necessary to create a custom editor and override the ComboBoxEdit.FindItem method. Source code of this method is shown below:
C#protected virtual int FindItem(string text, bool autoComplete, int startIndex) {
if(text == null) return -1;
startIndex = Math.Max(startIndex, 0);
if(text.Length == 0) {
for(int i = startIndex; i < Properties.Items.Count; ++i) {
if(string.Empty == GetItemDescription(Properties.Items[i])) return i;
}
} else {
if(!Properties.CaseSensitiveSearch) text = text.ToLower();
for(int i = startIndex; i < Properties.Items.Count; i++) {
string itemText = GetItemDescription(Properties.Items[i]);
if(!Properties.CaseSensitiveSearch) itemText = itemText.ToLower();
if(autoComplete)
itemText = itemText.Substring(0, Math.Min(itemText.Length, text.Length));
if(text == itemText && IsItemVisible(i))
return i;
}
}
return -1;
}
You are free to modify this code according to your scenario. However, I should note that this approach uses inner APIs that may be changed in the future. That is why we always recommend using only out of box solutions.
I have also passed your inquiry to our developers for consideration.
Hi,
Yes, we are using similar code for LookUpEdit as well:
C#protected virtual int FindItem(string text, bool partialSearch, int startIndex) {
if(text == null)
return -1;
if(text.Length == 0 && partialSearch)
return -1;
if(!Properties.CaseSensitiveSearch)
text = text.ToLower();
if(startIndex < 0)
startIndex = 0;
bool useStartsWith = Properties.GetFindFunction() == FunctionOperatorType.StartsWith;
for(int i = startIndex; i < Properties.DataAdapter.ItemCount; i++) {
string itemText = Properties.GetFindItemText(i);
if(!Properties.CaseSensitiveSearch)
itemText = itemText.ToLower();
if(partialSearch) {
if(useStartsWith) {
if(text == itemText.Substring(0, Math.Min(itemText.Length, text.Length)))
return i;
}
else {
if(itemText.IndexOf(text) != -1)
return i;
}
}
else {
if(text == itemText)
return i;
}
}
return -1;
}
Let me know if you have additional questions.
Hi,
The GetFindFunction, GetFindItemText, and DataAdapter members are protected and belong to the RepositoryItemLookUpEdit class. It means that you can use a standard technique with decorating new members with the new keyword to access the base members:
C#public class CustomRepositoryItemLookUpEdit: RepositoryItemLookUpEdit {
//...
public new FunctionOperatorType GetFindFunction() {
return base.GetFindFunction();
}
public new string GetFindItemText(int index) {
return base.GetFindItemText(index);
}
public new LookUpListDataAdapter DataAdapter {
get { return base.DataAdapter; }
}
}
Note that you need to use the approach described in the Custom editors help article to create a custom editor.
Keep in mind that this approach relies on inner APIs that may be modified or completely removed in the future.