RadAutoCompleteBox HighlightBehavior not working. One item is highlighted even if FindHighlightedIndex is returning -1.

4 posts, 0 answers
  1. Prasad
    Prasad avatar
    2 posts
    Member since:
    Nov 2017

    Posted 28 Nov Link to this post

    I want to disable all highlight in the RadAutoCompleteBox dropdown list. So I have HighlightBehavior.FindHighlightedIndex which returns -1. But, still one item in ItemsSource is highlighted. How can I fix it?

     

    FYI: On entering EACH new character in the search text box, we are calling a web service which returns a list of recommended search strings from history. (This behavior is similar to google search box.) And we set that list to ItemsSource property. This service call takes a few milliseconds.

    Observation: after hitting a new character in search box, FindHighlightedIndex is called, which returns -1, and after that, our service returns a new set of strings to be set in dropdown list, and that list is set to the ItemsSource property.  

     

    Kindly suggest how to fix this.

    Thanks.

     

    Our code snippet below:

    public class NoSuggestionItemHighlightBehavior : HighlightBehavior
    {
        public override int FindHighlightedIndex (string searchText, System.Collections.IList filteredItems, IEnumerable<object> escapedItems, string textSearchPath, TextSearchMode textSearchMode)
        {
           return -1;
        }
    }

     

    <telerik:RadAutoCompleteBox x:Name="textBox_Search"
    ItemsSource="{Binding AutoCompleteList}"
    SelectionMode="Single"
    TextSearchMode="Contains"
    BorderThickness="0"
    HighlightBehavior="{StaticResource NoSuggestionItemHighlightBehavior}"
    SearchText="{Binding SearchText, Mode=TwoWay}">

  2. Dinko
    Admin
    Dinko avatar
    462 posts

    Posted 01 Dec Link to this post

    Hello Prasad,

    Thank you for your interest in RadAutoCompleteBox control.

    I try to reproduce this behavior using custom HighlightBehavior but to no avail. Attached to this reply is the sample project which I used to test your scenario. In the attached project I have subscribed to KeyDown event of the control. Depending on which buttons are pressed (A,B,C) I am changing the ItemsSource so I can simulate your scenario and no item is highlighted. 

    Give this project a try and let me know if I am missing something from your implementation so I can reproduce this behavior on my side.

    Regards,
    Dinko
    Progress Telerik
    Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
  3. Prasad
    Prasad avatar
    2 posts
    Member since:
    Nov 2017

    Posted 07 Dec in reply to Dinko Link to this post

    Hi Dinko,

    Thanks for looking in to the issue I am facing.

    I can still reproduce it in your sample code.

    I kept only one suggention in textbox_Search_keyDown for A key down (Please see screen shot attached) and I executed the sample app and pressed 'A' in autoCompleteBox, I got one suggestion which was selected by default, even though we are returning -1 from CustomHighlightBehavior.

    Also, since one option is selected by default, that selected string appears in the autoCompleteText Box. We want to remove this behavior. Please refer attached screenshot.

     

    Thanks,

    Prasad.

  4. Dinko
    Admin
    Dinko avatar
    462 posts

    Posted 5 days ago Link to this post

    Hi Prasad,

    Indeed this is strange behavior as I wasn't able to reproduce it on my side. The highlight should not appear after you have set the custom HighlightBehavior to the HighlightBehavior property of the RadAutoCompleteBox. You can double check if this property is set in your main application.

    <Window.Resources>
        <local:MyHighlightBehavior x:Key="MyHighlightBehavior"/>
    </Window.Resources>
    <Grid>
        <telerik:RadAutoCompleteBox x:Name="textBox_Search"
                                    ItemsSource="{Binding Countries}"
                                    DisplayMemberPath="Name"
                                    SelectionMode="Single"
                                    TextSearchMode="Contains"
                                    HorizontalAlignment="Center"
                                    VerticalAlignment="Center"
                                    Width="200"
                                    BorderThickness="1"
                                    KeyDown="textBox_Search_KeyDown"
                                    HighlightBehavior="{StaticResource MyHighlightBehavior}"
                                    SearchText="{Binding SearchText, Mode=TwoWay}"/>
    </Grid>

    Can you confirm that the only modification which has done to the project attached to my previous reply is to just leave one item when you press "A" key from the keyboard?

    Regards,
    Dinko
    Progress Telerik
    Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
Back to Top