RadComboBox support of Home and End keys in editable mode

4 posts, 0 answers
  1. Irena
    Irena avatar
    3 posts
    Member since:
    May 2014

    Posted 01 May 2014 Link to this post

    Hi, 

    I have a control inhertited from RadComboBox control, QuickLaunch, with the following XAML definition:
     <Components:QuickLaunch x:Name="QuickSearchBar" DropDownWidth="Auto" MaxDropDownHeight="700" Width="200" EmptyText="Quick Launch (Ctrl + Q)" IsFilteringEnabled="True" CanAutocompleteSelectItems="False" IsTextSearchEnabled="True"
                                         TextSearchMode="Contains" telerik:TextSearch.TextPath="Label" SelectedValuePath="Label"  OpenDropDownOnFocus="True" StaysOpenOnEdit="True" IsEditable="True"  Controls1:RadToolBar.OverflowMode="Never" MaxWidth="300"
               >


    This control has code behind to support different categories and filtering.
    I would like to implement Key.Home and Key.End behavior, so that Home key will highlight the first element of the drop down, and End key the last element.  
    I created an override OnKeyDown method, where I tried to set SelectedIndex, SelectedItem, Items.View.MoveCurrentToFirst() (where Items is CollectionViewSource), but none of these solutions actually select the item in the combo box.  

    I have been able to trigger the OnSelectionChanged event, but what I want is to just highlight the item, and set focus to it, just like the current functionality of the PageUp/PageDown event.  Please advise.
      Irena





  2. Kalin
    Admin
    Kalin avatar
    1207 posts

    Posted 06 May 2014 Link to this post

    Hi Irena,

    What I can suggest you is to override the OnKeyDown method and once is fired to get the container of the desired item using the ItemContainerGenerator.ContainerFromIndex() method. Once you have the Item you would need to set its IsSelected property to true in order to select it as well as highlight it. Please check the following code snippet - I'm also checking if IsDropDownOpen and opening it if not (the drop down should be opened in order to have the containers generated):

    protected override void OnKeyDown(KeyEventArgs e)
    {
        if (e.Key == Key.Home)
        {
            if (!this.IsDropDownOpen)
            {
                // open the drop down if closed
                this.IsDropDownOpen = true;
            }
     
            Dispatcher.BeginInvoke(new Action(() =>
            {
                var firstComboBoxItem = this.ItemContainerGenerator.ContainerFromIndex(0) as RadComboBoxItem;
                firstComboBoxItem.IsSelected = true;
            }));
        }
        else if (e.Key == Key.End)
        {
            if (!this.IsDropDownOpen)
            {
                // open the drop down if closed
                this.IsDropDownOpen = true;
            }
     
            Dispatcher.BeginInvoke(new Action(() =>
            {
                var firstComboBoxItem = this.ItemContainerGenerator.ContainerFromIndex(this.Items.Count - 1) as RadComboBoxItem;
                firstComboBoxItem.IsSelected = true;
            }));
        }
     
        base.OnKeyDown(e);
    }

    Hope this will help you to achieve the required.

    Regards,
    Kalin
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
  3. DevCraft banner
  4. Irena
    Irena avatar
    3 posts
    Member since:
    May 2014

    Posted 06 May 2014 in reply to Kalin Link to this post

    Hi Kalin, 
    I tried your approach, but it did not work.  The item gets selected and triggers OnSelectionChanged  event, which then opens the selected item.  However, all I want is to just highlight the item, and make it visible in the drop down, just like your current up/down and pageUp/pageDown keys work.  
  5. Kalin
    Admin
    Kalin avatar
    1207 posts

    Posted 08 May 2014 Link to this post

    Hello Irena,

    I'm afraid that the highlighting of the items is done internally and with the current implementation of the ComboBox is not possible to achieve the desired scenario other way. You will need to select the item at same time. However I logged that as a feature request in our Feedback portal, so you can easily vote and track its status on the following link:
    http://feedback.telerik.com/Project/143/Feedback/Details/127590-make-posible-to-set-the-combobox-highlighted-comboboxitem-through-the-code

    Hope this helps.

    Regards,
    Kalin
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
Back to Top