With this blog we will implement the following scenarios in C1ComboBox :
Here, we will test for the property values IsKeyboardFocused and IsKeyboardFocusWithin and if either of them is true then will open the DropDown.
void c1ComboBox_IsKeyboardFocusedChanged(object sender, DependencyPropertyChangedEventArgs e)
{
UpdateFocus();
}
void c1ComboBox_IsKeyboardFocusWithinChanged(object sender, DependencyPropertyChangedEventArgs e)
{
UpdateFocus();
}
private void UpdateFocus()
{
this.Dispatcher.BeginInvoke(new Action(delegate
{
// handle both properties, as ComboBox is complicated control, can have different combination of this properties
if (c1ComboBox.IsKeyboardFocused || c1ComboBox.IsKeyboardFocusWithin)
{
c1ComboBox.IsDropDownOpen = true;
}
else
{
c1ComboBox.IsDropDownOpen = false;
}
}));
}
We will make use of the SelectedItemChanged event in here and after selecting the respective Item from the underlying ObservableCollection, will insert it at the zeroth index in the Collection.
int index;
void c1ComboBox_SelectedItemChanged(object sender, C1.WPF.PropertyChangedEventArgs<object> e)
{
//Get the index position of the currently selected item in the ComboBox
index = c1ComboBox.SelectedIndex;
//Get the Item
Employee emp1 = (Employee)c1ComboBox.SelectedItem;
if (index >= 0)
{
c1ComboBox.ItemsSource = null;
//Remove the item from its original index in the Collection
emp.RemoveAt(index);
//Insert it in the first place in the Collection
emp.Insert(0, emp1);
c1ComboBox.ItemsSource = emp;
}
}