开发者

select combobox item by pressing enter key in c# windows aplication

开发者 https://www.devze.com 2023-04-13 05:55 出处:网络
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

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号