ComboBox Events
The ComboBox type exposes the following members.
| Name | Description | |
|---|---|---|
|
AutoSizeChanged | Infrastructure. This event is not relevant for this class. (Inherited from Control.) |
|
BackColorChanged | Occurs when the value of the BackColor property changes. (Inherited from Control.) |
|
BackgroundImageChanged | Infrastructure. Occurs when the value of the BackgroundImage property changes. |
|
BackgroundImageLayoutChanged | Infrastructure. Occurs when the BackgroundImageLayout property changes. |
|
BindingContextChanged | Occurs when the value of the BindingContext property changes. (Inherited from Control.) |
|
CausesValidationChanged | Occurs when the value of the CausesValidation property changes. (Inherited from Control.) |
|
ChangeUICues | Occurs when the focus or keyboard user interface (UI) cues change. (Inherited from Control.) |
|
Click | Occurs when the control is clicked. (Inherited from Control.) |
|
ClientSizeChanged | Occurs when the value of the ClientSize property changes. (Inherited from Control.) |
|
ContextMenuChanged | Occurs when the value of the ContextMenu property changes. (Inherited from Control.) |
|
ContextMenuStripChanged | Occurs when the value of the ContextMenuStrip property changes. (Inherited from Control.) |
|
ControlAdded | Occurs when a new control is added to the Control.ControlCollection. (Inherited from Control.) |
|
ControlRemoved | Occurs when a control is removed from the Control.ControlCollection. (Inherited from Control.) |
|
CursorChanged | Occurs when the value of the Cursor property changes. (Inherited from Control.) |
|
DataSourceChanged | Occurs when the DataSource changes. (Inherited from ListControl.) |
|
DisplayMemberChanged | Occurs when the DisplayMember property changes. (Inherited from ListControl.) |
|
Disposed | Occurs when the component is disposed by a call to the Dispose method. (Inherited from Component.) |
|
DockChanged | Occurs when the value of the Dock property changes. (Inherited from Control.) |
|
DoubleClick | Infrastructure. This event is not relevant for this class. |
|
DragDrop | Occurs when a drag-and-drop operation is completed. (Inherited from Control.) |
|
DragEnter | Occurs when an object is dragged into the control's bounds. (Inherited from Control.) |
|
DragLeave | Occurs when an object is dragged out of the control's bounds. (Inherited from Control.) |
|
DragOver | Occurs when an object is dragged over the control's bounds. (Inherited from Control.) |
|
DrawItem | Occurs when a visual aspect of an owner-drawn ComboBox changes. |
|
DropDown | Occurs when the drop-down portion of a ComboBox is shown. |
|
DropDownClosed | Occurs when the drop-down portion of the ComboBox is no longer visible. |
|
DropDownStyleChanged | Occurs when the DropDownStyle property has changed. |
|
EnabledChanged | Occurs when the Enabled property value has changed. (Inherited from Control.) |
|
Enter | Occurs when the control is entered. (Inherited from Control.) |
|
FontChanged | Occurs when the Font property value changes. (Inherited from Control.) |
|
ForeColorChanged | Occurs when the ForeColor property value changes. (Inherited from Control.) |
|
Format | Occurs when the control is bound to a data value. (Inherited from ListControl.) |
|
FormatInfoChanged | Occurs when the value of the FormatInfo property changes. (Inherited from ListControl.) |
|
FormatStringChanged | Occurs when value of the FormatString property changes (Inherited from ListControl.) |
|
FormattingEnabledChanged | Occurs when the value of the FormattingEnabled property changes. (Inherited from ListControl.) |
|
GiveFeedback | Occurs during a drag operation. (Inherited from Control.) |
|
GotFocus | Occurs when the control receives focus. (Inherited from Control.) |
|
HandleCreated | Occurs when a handle is created for the control. (Inherited from Control.) |
|
HandleDestroyed | Occurs when the control's handle is in the process of being destroyed. (Inherited from Control.) |
|
HelpRequested | Occurs when the user requests help for a control. (Inherited from Control.) |
|
ImeModeChanged | Occurs when the ImeMode property has changed. (Inherited from Control.) |
|
Invalidated | Occurs when a control's display requires redrawing. (Inherited from Control.) |
|
KeyDown | Occurs when a key is pressed while the control has focus. (Inherited from Control.) |
|
KeyPress | Occurs when a key is pressed while the control has focus. (Inherited from Control.) |
|
KeyUp | Occurs when a key is released while the control has focus. (Inherited from Control.) |
|
Layout | Occurs when a control should reposition its child controls. (Inherited from Control.) |
|
Leave | Occurs when the input focus leaves the control. (Inherited from Control.) |
|
LocationChanged | Occurs when the Location property value has changed. (Inherited from Control.) |
|
LostFocus | Occurs when the control loses focus. (Inherited from Control.) |
|
MarginChanged | Occurs when the control's margin changes. (Inherited from Control.) |
|
MeasureItem | Occurs each time an owner-drawn ComboBox item needs to be drawn and when the sizes of the list items are determined. |
|
MouseCaptureChanged | Occurs when the control loses mouse capture. (Inherited from Control.) |
|
MouseClick | Occurs when the control is clicked by the mouse. (Inherited from Control.) |
|
MouseDoubleClick | Occurs when the control is double clicked by the mouse. (Inherited from Control.) |
|
MouseDown | Occurs when the mouse pointer is over the control and a mouse button is pressed. (Inherited from Control.) |
|
MouseEnter | Occurs when the mouse pointer enters the control. (Inherited from Control.) |
|
MouseHover | Occurs when the mouse pointer rests on the control. (Inherited from Control.) |
|
MouseLeave | Occurs when the mouse pointer leaves the control. (Inherited from Control.) |
|
MouseMove | Occurs when the mouse pointer is moved over the control. (Inherited from Control.) |
|
MouseUp | Occurs when the mouse pointer is over the control and a mouse button is released. (Inherited from Control.) |
|
MouseWheel | Occurs when the mouse wheel moves while the control has focus. (Inherited from Control.) |
|
Move | Occurs when the control is moved. (Inherited from Control.) |
|
PaddingChanged | Infrastructure. This event is not relevant to this class. |
|
Paint | Infrastructure. Occurs when the ComboBox control is redrawn. |
|
ParentChanged | Occurs when the Parent property value changes. (Inherited from Control.) |
|
PreviewKeyDown | Occurs before the KeyDown event when a key is pressed while focus is on this control. (Inherited from Control.) |
|
QueryAccessibilityHelp | Occurs when AccessibleObject is providing help to accessibility applications. (Inherited from Control.) |
|
QueryContinueDrag | Occurs during a drag-and-drop operation and enables the drag source to determine whether the drag-and-drop operation should be canceled. (Inherited from Control.) |
|
RegionChanged | Occurs when the value of the Region property changes. (Inherited from Control.) |
|
Resize | Occurs when the control is resized. (Inherited from Control.) |
|
RightToLeftChanged | Occurs when the RightToLeft property value changes. (Inherited from Control.) |
|
SelectedIndexChanged | Occurs when the SelectedIndex property has changed. |
|
SelectedValueChanged | Occurs when the SelectedValue property changes. (Inherited from ListControl.) |
|
SelectionChangeCommitted | Occurs when the selected item has changed and that change is displayed in the ComboBox. |
|
SizeChanged | Occurs when the Size property value changes. (Inherited from Control.) |
|
StyleChanged | Occurs when the control style changes. (Inherited from Control.) |
|
SystemColorsChanged | Occurs when the system colors change. (Inherited from Control.) |
|
TabIndexChanged | Occurs when the TabIndex property value changes. (Inherited from Control.) |
|
TabStopChanged | Occurs when the TabStop property value changes. (Inherited from Control.) |
|
TextChanged | Occurs when the Text property value changes. (Inherited from Control.) |
|
TextUpdate | Occurs when the control has formatted the text, but before the text is displayed. |
|
Validated | Occurs when the control is finished validating. (Inherited from Control.) |
|
Validating | Occurs when the control is validating. (Inherited from Control.) |
|
ValueMemberChanged | Occurs when the ValueMember property changes. (Inherited from ListControl.) |
|
VisibleChanged | Occurs when the Visible property value changes. (Inherited from Control.) |
Since I couldn't find this information anywhere else...
For a ComboBox with the following settings, the order of events is as follows:
Settings
AutoCompleteMode----------Suggest
AutoCompleteSource--------ListItems
DataSource-------------------System.Windows.Forms.BindingSource
DisplayMember--------------[Database field]
DropDownStyle--------------DropDownList
ValueMember----------------[Database field]
Others as default
Form Load
1. DisplayMemberChanged
2. ValueMemberChanged
3. SelectedValueChanged
4. SelectedValueChanged
5. SelectedValueChanged
6. SelectedValueChanged (repeats four times)
Click on Control (gets focus)
1. Enter
[dropped down list then appears]
Choose a List Item with Mouse Click
[dropped down list retracts]
1. TextChanged
2. SelectionChangeCommitted
3. SelectedValueChanged
4. SelectedIndexChanged
Change the List Item with the Mouse Scroll Wheel
1. SelectionChangeCommitted
2. SelectedValueChanged
3. SelecetdIndexChanged
Note: The TextChanged event does not fire with the scroll wheel as it does via mouse clicks on the dropped down list
Exit Control (loses focus)
1. Leave
2. Validating
3. Validated
Form Close
1. TextChanged
2. SelectedValueChanged
3. SelectedIndexChanged
4. DisplayMemberChanged
Qualifying Comments
I did not test all events, only those I thought might fire (and where relevant to my issue) during form load, user interaction and form close. Therefore I tested the following:
DisplayMemberChanged
Enter
Leave
SelectedIndexChanged
SelectedValueChanged
SelectionChangeCommitted
TextChanged
TextUpdate
Validated
Validating
ValueMemberChanged
Therefore other events might have been firing but I was not handling them in my testing.
My reason for the testing was that the ComboBox selection needed to cause a 2nd ComboBox to be filtered (BindingSource.Filter property) and it caused an exception on Form Close* and didn't work with the scroll wheel. It would also have been useful if the 2nd ComboBox would filter correctly on Form Load based on the default value of the ComboBox I was handling.
Analysis of the above led me to use SelectionChangeCommitted since it fired when the user selected a value via mouse clicks or via the scroll wheel but did not fire on Form Close. I could not see an option that also fired during Form load (but not in Form Close, since avoiding the exception was higher priority) so I added the same line of filtering code that is in the SelectionChangeCommitted handler to the Form Load handler.
Private Sub cmbRegion_SelectionChangeCommitted(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbRegion.SelectionChangeCommitted
Me.Countries_BindingSource.Filter = "[region_id] = '" & Me.cmbRegion.SelectedValue.ToString & "'"
End Sub
* I believe the NullReferenceException was being caused during Form Close due to the BindingSource component for the 2nd ComboBox being destroyed before the ComboBox I was handling and hence using the TextChanged event I would be trying to refer to a BindingSource that had been destroyed, but I can't be sure.