ComboBox not losing focus
Solution 1
You may want to take a look at This topic. Try setting CausesValidation to false on the combo box, see if you can leave it. If an exception is thrown in the OnValidating event handler, it won't deselect the box.
Solution 2
All you have to do is:
- go to property window of Combobox
- and set Allow Drop="true"
The property is intended for some other purpose but it works for this scenario too.
Solution 3
Are you sure the problem isn't because neither your frame or your other combobox have a way to gain focus?
Solution 4
So what exactly are you saying? Are you saying that your _LostFocus() event handler is not being called? If so, the first place I would look is in your designer-generated event handler mapping code. Sometimes that has a way of being disassociated by doing certain things in the designer (it's rare these days, though...)
Solution 5
I experienced a similar problem, but the control was recursively losing and regaining focus; the LostFocus
event handler was being called, but the control immediately regained focus. Setting the CausesValidation
property to false
had no effect.
In my case, I had bound to the SelectedValue
property instead of the Text
property when binding to a custom object. Because I manually specified the ComboBox item collection and did not provide a data source, the ValueMember
property was missing or invalid (so of course the SelectedValue
property was no use.)
Changing my binding to use the Text
property solved the issue.
tomzx
Updated on July 13, 2022Comments
-
tomzx almost 2 years
I've been having problems with the ComboBox control. I'm no expert in GUI, but I know this problem is related to the control's focus.
For some reason, the ComboBox does not lose its focus when I click outside of it. Say for example:
- I click on the ComboBox to list its items.
- I select one item. This closes the ComboBox.
- I click on the second ComboBox, the first one stays focused.
OR
- Click on a ComboBox (contains Point, Solid and Wireframe).
- Click on the form. Press either P, S or W. See the selection get changed.
Note that the ComboBox only has the DropDownStyle set to ComboBoxStyle.DropDownList. This means that it's the default ComboBox behavior. I thought that the default behavior was that the ComboBox would lose its focus when you clicked out of it, or on another control (button or ComboBox). It is not the case here, why?
UPDATE: What I need is some sort of ActiveComponent = null. The behavior should be similar to the one of Visual Studio were you select Debug or Release (ComboBox) in the standard toolbar. Currently, if I click outside of the ComboBox, it is still focused.
-
tomzx almost 15 yearsI do not have defined any custom Leave event for the ComboBox, but if I do and set breakpoints, I can see it's clearly not called.
-
Rob over 14 yearsFor my purposes I ended up choosing SelectedItem over Text, because apparently the TextChanged event only fires when the collection item is selected by the mouse, and not the keyboard. SelectedIndexChanged seems to fire regardless of input device.
-
JAL about 8 yearsPlease elaborate on how this code answers the question.
-
Taja_100 about 8 yearsif we have two controls eg combobox and another grid...mark the tabindex 1 for combobox and 2 for grid....then after selecting value from combobox and press enter ...then the tab key used to function in the case of combobox so the combobox lose the focus and grid on focus.
-
Olivier Jacot-Descombes almost 8 yearsI had the same problem with a TextBox being the only focusable control on a UserControl. Setting
AllowDrop=true
magically solved the problem.