dcsimg
Login | Register   
LinkedIn
Google+
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

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


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

WEBINAR:

On-Demand

Building the Right Environment to Support AI, Machine Learning and Deep Learning


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
Thanks for your registration, follow us on our social networks to keep up-to-date