select combobox item by pressing enter key in c# windows aplication
In c#, I want to s开发者_开发百科elect combo box items by keyboard and when i press enter after selecting one that item should be selected. how to do it?
try something like this ..., this will explain how to change the items using mouse and key board ,....
I found this method worked fine in all the conditions. But I m not sure if anything more accurate than this method is available.
bool IsMouse = false;
private void cmbMy_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (IsMouse)
{
//Write the logic if selection is changed by mouse
}
else
{
//Write the logic if selection is changed by keyboard
}
IsMouse = false;
}
private void cmbMy_IsMouseCapturedChanged(object sender, DependencyPropertyChangedEventArgs e)
{
IsMouse = true;
}
In isMouseCapturedChanged event of combo box i made a bool variable true and when selection changed of the combo box i m checking the bool doing the required task and then setting isMouse to false.
Or you need to bulid your own custom combobox ..
You need build a custom ComboBox class and override the Control.ProcessKeyEventArgs Method.
精彩评论