Ticket T742841
Visible to All Users

ComboBoxEdit - How to search with unicode characters and user defined comparison

created 6 years ago

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

Answers approved by DevExpress Support

created 6 years ago

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.

    Show previous comments (2)
    DevExpress Support Team 6 years ago

      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.

      C C
      Corne (Paralax) 6 years ago

        Some functions are not usable because of the class protection

        DevExpress Support Team 6 years ago

          Hi,

          The GetFindFunctionGetFindItemText, 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.

          Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

          Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.