This is a migrated thread and some comments may be shown as answers.

RadComboBox support of Home and End keys in editable mode

3 Answers 67 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Irena
Top achievements
Rank 1
Irena asked on 01 May 2014, 09:40 PM
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





3 Answers, 1 is accepted

Sort by
0
Kalin
Telerik team
answered on 06 May 2014, 12:17 PM
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.
 
0
Irena
Top achievements
Rank 1
answered on 07 May 2014, 01:16 AM
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.  
0
Kalin
Telerik team
answered on 08 May 2014, 11:03 AM
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.
 
Tags
ComboBox
Asked by
Irena
Top achievements
Rank 1
Answers by
Kalin
Telerik team
Irena
Top achievements
Rank 1
Share this question
or