Solved

WPF combobox selectionchanged event only on mouse click?

Posted on 2010-11-22
3
8,505 Views
Last Modified: 2012-05-10
Hi Guys,

I have a ComboBox in my WPF xaml with some predefined ComboBoxItems. The ComboBox has the IsEditable enabled, so you can type in your username or select one from the predefined dropdown list of existing users on this system.

When the user is selected I would like the focus to be transferred on the password field, but I'm having some difficulties with it since the combobox fires the selectionchanged event if i type in the first letter of a matching item in the ComboBoxItem or if I try to cycle through the predefined values using the up / down arrow keys. It's understandable that it does that since the selection of it has been changed, but I would like to know how could I filter my SelectionChanged event to pass the focus to my password input only if the user clicks on the item form the ComboBox, not if the item is autosuggested or cycled through with arrow keys. A good example of the user input field that I am trying to achieve is the Skype "Skype Name" component in the Skype Sign In screen.

WPF xaml code:
<ComboBox  IsEditable="True" IsReadOnly="False" HorizontalAlignment="Left"  Name="UserInput"  Grid.ColumnSpan="2" " StaysOpenOnEdit="True" SelectionChanged="UserInput_SelectionChanged">
                            <ComboBoxItem Content="test" />
                            <ComboBoxItem Content="abc" />
                            <ComboBoxItem Content="xyz" />
</ComboBox>

Open in new window


C# Code:
private void UserInput_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            
            PasswordInput.Focus();
        }

Open in new window


I've also tried the preview on key event returning the e.handled which worked fine, but it disabled the functionality of manually inputting a new value to the ComboBox:
private void UserInput_PreviewKeyDown(object sender, System.Windows.Input.KeyEventArgs e)
        {
            e.Handled = true;
        }

Open in new window


Thank you for your help,
0
Comment
Question by:xNejX
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 20

Expert Comment

by:Daniel Van Der Werken
ID: 34187569
I don't have WPF on my system, but I think I know what you're talking about and might offer a suggestion.

What I would do is set the OnMouseDown event for the combo box itself and then set a class-wide static bool variable to true if the mouse button was pushed while the cursor was over the combo box.

Then, in the OnSelectionChanged event, I'd check to see if the mouse had been previously pushed down.  If so, then I'd do the move to the password box.

Make sure to reset the bool value to false as appropriate.  You might have to tinker around with it.  Anyway, that's what I'd do. There might be a more elegant solution.
0
 
LVL 29

Accepted Solution

by:
Kumaraswamy R earned 500 total points
ID: 34194360
0
 

Author Closing Comment

by:xNejX
ID: 34196724
just perfect :)
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question