Login | Register   
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: VB.NET
Expertise: Beginner
May 4, 2004

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 Sub

Private Sub CombBox1_SelectedIndexChanged _
(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles CombBox1.SelectedIndexChanged

	'Event code
	'Do some code here ... fires off prematurely

End 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
David Acree
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap