This page looks best with JavaScript enabled

VB.NET - DropDownOpening Event For ComboBox

 ·   ·  ☕ 1 min read

Here is a proper way to do it - inherit a class from native ComboBox and override OnDropDown to raise a custom DropDownOpening event first:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
Public Class MyComboBox : Inherits ComboBox
  Public Event DropDownOpening(sender As Object, e As System.EventArgs)

  Protected Overrides Sub OnDropDown(e As System.EventArgs)
    RaiseEvent DropDownOpening(Me, e)
    MyBase.OnDropDown(e)
  End Sub
End Class

Private Sub MyComboBox1_DropDownOpening(sender As Object, e As System.EventArgs) Handles MyComboBox1.DropDownOpening
  'reload your list here
  '...
End Sub

If you anticipate loading to take considerable time, you can wrap your reload code into a construct like this:

1
2
3
4
5
Dim oldCursor As Cursor = MyComboBox1.Cursor
MyComboBox1.Cursor = Cursors.WaitCursor
'reload your list here
'...
MyComboBox1.Cursor = oldCursor

(DoEvents is not needed to propagate cursor change)


Victor Zakharov
WRITTEN BY
Victor Zakharov
Web Developer (Angular/.NET)