Hello,
I have a question about traversing the focus when a selection is made in the RadComboBox.
I have the following requirement:
When the user enters the combobox, the drop down should automatically open (I set OpenDropDownOnFocus= true) , the user will select an item and confirm the selection by using the enter key. After that the item should be set, the drop down should be closed and the focus should automatically traverse to the next field. Travesersing focus to the next field should be done by the enter-key, I already implemented this for textboxes.
I have used below code with the regular WPF ComboBox, but this gave some unexpected behavior in the past.
Sometimes the warning was shown ("Couldn't move the focus.......) and the user was not able anymore to traverse the focus in the whole screen using the enter key, he needed to close the screen and open it again to re-enable this functionality.
public
class
CustomComboBox : ComboBox
{
#region Fields
private
bool
_focused =
false
;
#endregion
#region Methods
protected
override
void
OnGotKeyboardFocus(KeyboardFocusChangedEventArgs e)
{
base
.OnGotKeyboardFocus(e);
_focused =
true
;
}
protected
override
void
OnDropDownClosed(EventArgs e)
{
if
(_focused)
{
var uie =
this
as
UIElement;
_focused =
false
;
}
else
{
base
.OnDropDownClosed(e);
}
}
protected
override
void
OnKeyDown(KeyEventArgs e)
{
if
((e.Key == System.Windows.Input.Key.Enter))
{
base
.OnKeyDown(e);
var comboBoxItem = e.OriginalSource
as
FrameworkElement;
var comboBox = ItemsControl.ItemsControlFromItemContainer(comboBoxItem)
as
ComboBox;
if
(comboBox !=
null
)
comboBox.MoveFocus(
new
TraversalRequest(FocusNavigationDirection.Next));
else
{
LogManager.GetLog(
this
.GetType()).Warn(
"Couldn't move the focus to the next field, source: {0}."
, e.OriginalSource);
}
}
else
base
.OnKeyDown(e);
}
#endregion
}
What is the best way to accomplish this, or is this functionality already in the RadComboBox?
Regards,
Marcel