How to select the items in comboxbox using key up/down?
I tried to handle it in PreviewKeyDown event. But it is not working.
How to select the items in comboxbox using key up/down?
I tried to handle it in PreviewKeyDown event. But it is not working.
Keyboard navigation is already present for any control deriving from Selector as the CoboBox does. The control has to have focus before it will capture the key events as well. Are you trying to do something other then select/scroll through the items? Because it already does that.
I fully agree with the above answer. First you have to select the control.
e.g.
Here is a sample xaml code
<Page x:Class="CascadingDropDown.Page1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Page1" Loaded="Page_Loaded"> <Grid> <ComboBox Height="23" Margin="60,32,120,0" Name="comboBox1" VerticalAlignment="Top" DisplayMemberPath="CountryNames" ItemsSource="{Binding}" IsSynchronizedWithCurrentItem="True"/> </Grid> </Page>
In the .CS file add the following
private void Page_Loaded(object sender, RoutedEventArgs e)
{
comboBox1.DataContext = CountryTable();
comboBox1.Focus();
}
private DataTable CountryTable()
{
DataTable dt = new DataTable();
dt.Columns.Add("CountryNames");
dt.Rows.Add("India");
dt.Rows.Add("Australia");
dt.Rows.Add("Canada");
dt.Rows.Add("USA");
return dt;
}
So after loading, you will find that the combo is selected. Use the up / down arrow key for the items to be selected