devxlogo

Determine Whether a Combobox Is Being Loaded

Determine Whether a Combobox Is Being Loaded

Say you have a combobox being loaded at form initialization from a database and you have code in the combobox’s SelectedIndexChanged event. This may cause unwanted exceptions:

Private Sub LoadComboBox()	'Connection and SQL code	'...         ComboBox1.ValueMember = "ID"         ComboBox1.DisplayMember = "Customer"         ComboBox1.DataSource = ds.Tables("Customers")	'Clean up code	'...End SubPrivate Sub CombBox1_SelectedIndexChanged _(ByVal sender As System.Object, ByVal e As System.EventArgs) _Handles CombBox1.SelectedIndexChanged	'Event code	'Do some code here ... fires off prematurelyEnd Sub

There is a way to avoid this premature code firing?without having to do any custom handling.

The combobox’s Created property can determine if the control’s creation process (loading) is done yet. The only problem is, the Created Property doesn’t show up in the Intellisense List!

Private Sub CombBox1_SelectedIndexChanged _(ByVal sender As System.Object, ByVal e As System.EventArgs) _Handles CombBox1.SelectedIndexChanged	'Prevents premature execution of event code	If Me.ComboBox1.Created = True Then			'Event code		'Do some code here	End If End Sub
See also  Why ChatGPT Is So Important Today
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist