Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7657417
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:01:46+00:00 2026-05-31T13:01:46+00:00

When the user is selecting values from a combobox, if they choose a value,

  • 0

When the user is selecting values from a combobox, if they choose a value, the “SelectionChanged” event fires and the new value is set and everything’s fine. If, however, they decide not to change the value and click elsewhere on the UI (like a text box they want to edit), they have to click twice – the first click simply closes the combobox popup, and the next click will focus the element they wanted to activate on the first click.

How can I prevent the combobox popup from hijacking the focus target on the first click like that?

I’ve tried monitoring the ComboBox_LostFocus event, but this fires at the wrong time. When the user clicks the dropdown and the popup list is displayed, the ComboBox_LostFocus event fires – it’s losing focus to it’s own dropdown list. I don’t want to do anything to change that. When the user then clicks away and the popup closes, the ComboBox never regains focus (focus is just ‘lost’ to everything) and so this event is useless.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T13:01:48+00:00Added an answer on May 31, 2026 at 1:01 pm

    I think I might have found a solution. Comboboxes do have a DropDownClosed event – the problem is it isn’t a RoutedEvent, so you can’t create a style for ComboBoxes and have them all inherit the event via an EventSetter. (You get the error 'DropDownClosed' must be a RoutedEvent registered with a name that ends with the keyword "Event")

    However, the Loaded event is a RoutedEvent, so we can hook into that in the style:

    <Style x:Key="ComboBoxCellStyle" TargetType="ComboBox">
        <EventSetter Event="Loaded" Handler="ComboBox_Loaded" />
    </Style>
    

    Now that we have an event that will always fire before anything else is done with the ComboBox, we can hook into the event we actually care about:

    private void ComboBox_Loaded(object sender, RoutedEventArgs e)
    {
        ((ComboBox)sender).DropDownClosed -= ComboBox_OnDropDownClosed;
        ((ComboBox)sender).DropDownClosed += new System.EventHandler(ComboBox_OnDropDownClosed);
    }
    

    Now that I finally have access to the event that fires when the DropDown is closing, I can perform whatever actions I need to make sure the focus is terminated on the bothersome ComboBox. In my case, the following:

    void ComboBox_OnDropDownClosed(object sender, System.EventArgs e)
    {
        FrameworkElement visualElement = (FrameworkElement)sender;
    
        while( visualElement != null && !(visualElement is DataCell) )
            visualElement = (FrameworkElement)visualElement.TemplatedParent;
        if( visualElement is DataCell )
        {
            DataCell dataCell = (DataCell)visualElement;
            dataCell.EndEdit();
            if( !(dataCell.ParentRow is InsertionRow) ) dataCell.ParentRow.EndEdit();
        }
    }
    

    I had a ComboBox as the template of a DataCell in a GridView, and this particular problem was preventing the DataRow from ending edit when the user popped open a ComboBox then clicked outside of the grid.

    That was my biggest problem with this bug. A secondary problem setting the focus in this event iff the user clicked. The combobox might also have just been closed because the user hit tab or escape though, so we can’t just setfocus to the mouse position. We’d need more information on what caused the DropDownClosed event to fire. Probably means hooking into more unrouted events in the _Loaded event handler.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to prevent user from selecting text (select all or select a portion
I am selecting the user's information from my MySQL database as shown below: SELECT
In my application I want to give the user ways of selecting text from
I have a html form which the user inputs values/selects options. After selecting, these
I want to let the user select a value from a combo box, and
I'm having bit of a trouble selecting correct values from my mysql sql server.
I have a combobox that is populated at runtime with values from a loadoperation
I need to display 3 rows from which a user can pick values by
I have a tableView and when the user is selecting one of the cells,
I'm trying to write a faster user switching app for Windows. Win+L and selecting

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.