RadComboBox Autocomplete removes first character

5 posts, 1 answers
  1. iahulg
    iahulg avatar
    7 posts
    Member since:
    Jan 2016

    Posted 30 Mar Link to this post

    Hi 
    I need to implement RadComboBox Autocomplete after 2 chars entered..

    After I enter the second char it removes the first char and shows the popup (see attachment).
    Any ideas how to handle this ?

    Codebehind:

     

    1.private void RadComboBox_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
    2.{
    3.      var combo = sender as RadComboBox;
    4.      if (!combo.IsDropDownOpen && combo.Text?.Length >=1)
    5.         {
    6.           combo.IsDropDownOpen = true;
    7.         }
    8.}

     

    XAML:

     

    01.<telerik:RadComboBox ItemsSource="{Binding PickTickets}"
    02.                        DisplayMemberPath="PickTicketIdentity"
    03.                        EmptyText="Please select a pick ticket"<br>
    04.                        IsEditable="True"
    05.                        IsFilteringEnabled="True"
    06.                        TextSearchMode="Contains"
    07.                        CanAutocompleteSelectItems="False"
    08.                        StaysOpenOnEdit="True"
    09.                        SelectedItem="{Binding SelectedPickTicket}"
    10.                        KeyDown="RadComboBox_KeyDown"/> 

  2. Pavel
    Pavel avatar
    2 posts
    Member since:
    Nov 2012

    Posted 30 Mar Link to this post

    Works with 

     private void combo_TextChanged(object sender, TextChangedEventArgs args)
    {
        var combo = sender as RadComboBox;
        if (!combo.IsDropDownOpen && combo.Text?.Length >= 2)
        {
           combo.IsDropDownOpen = true;  
        }
    }

     

    TextBoxBase.TextChanged="combo_TextChanged" SelectAllTextEvent="None"

  3. UI for WPF is Visual Studio 2017 Ready
  4. Pavel
    Pavel avatar
    2 posts
    Member since:
    Nov 2012

    Posted 30 Mar Link to this post

    But doesn't work with 

    CanAutocompleteSelectItems="False"

    as it selects the first line with 'PK...' as soon as I enter 'pk'

     

  5. Answer
    Yana
    Admin
    Yana avatar
    4554 posts

    Posted 31 Mar Link to this post

    Hi Vitali,

    Regarding CanAutocompleteSelectItems - please note that this property is applicable only when the DropDown of the ComboBox is open.

    So, in the concrete case, I have tested the provided code with a two way binding of the SelectedItem property and it is not updated when the dropdown is open and CanAutocompleteSelectItems is false.
    It is expected that the first found item that match the entered text will be highlighted.

    Could you please describe the expected result, so we to be able to provide proper assistance?

    Regards,
    Yana
    Telerik
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
  6. iahulg
    iahulg avatar
    7 posts
    Member since:
    Jan 2016

    Posted 31 Mar in reply to Yana Link to this post

    Hi, Yana. 
    Thanks you for your reply.
    I actually managed to solve this issue using another control:
    XAML:
    <telerik:RadAutoCompleteBox ItemsSource="{Binding PickTickets}"
                       SelectedItem="{Binding SelectedPickTicket, Mode=TwoWay }"
                       DisplayMemberPath="PickTicketIdentity"
                       MinWidth="100"
                       TextSearchMode="Contains"
                       AutoCompleteMode="Suggest"
                       SelectionMode="Single"
                       KeyUp="RadAutoCompleteBox_KeyUp"/>

    Codebehind:
    private void RadAutoCompleteBox_KeyUp(object sender, System.Windows.Input.KeyEventArgs e)
    {
          var racb = sender as RadAutoCompleteBox;
          if (!racb.IsDropDownOpen && racb.SearchText?.Length >= 2)
          {
              racb.IsDropDownOpen = true;
          } else if (racb.IsDropDownOpen && racb.SearchText?.Length < 2)
          {
              racb.IsDropDownOpen = false;
          }
    }
Back to Top
UI for WPF is Visual Studio 2017 Ready