Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Inheriting From mmComboBox
Message
 
À
23/08/2004 10:12:53
Information générale
Forum:
ASP.NET
Catégorie:
The Mere Mortals .NET Framework
Divers
Thread ID:
00935575
Message ID:
00935601
Vues:
21
This message has been marked as the solution to the initial question of the thread.
>The code below compiles, however, when I drop the component on a windows form in designer view I get "an exception occurred while trying to create an instance of CsiDataBoundCombos.StateCombo. The exception was object reference not set to an instance of an object."

The problem here is that VS .NET runs a component's constructor at design time. It can't run the following code you have in your constructor at design time (and you really don't want it to) because all the objects it needs are not available:
Public Sub New()
	MyBase.New()
	bizObject = New Csi.Biz.States

	InitializeComponent()

	Me.ValueMember = "StateCode"
	Me.DisplayMember = "Description"
	Me.DataSource = bizObject.GetAll().Tables(0)
End Sub
What you need to do is bracket this code in an If statement that determines whether or not you are in design mode. All .NET Controls have a DesignMode property...unfortunately, its value is not set during instantiation! To solve this problem we have added a static/shared IsRunning property to the MM .NET mmAppBase class that you can use instead. For example:
Public Sub New()
	MyBase.New()
	bizObject = New Csi.Biz.States

	InitializeComponent()

	If mmAppBase.IsRunning Then
	   Me.ValueMember = "StateCode"
	   Me.DisplayMember = "Description"
	   Me.DataSource = bizObject.GetAll().Tables(0)
	End If

End Sub
Check out the MM .NET Help topic "Why do I get errors when I open a component in design mode?" for more information.
Kevin McNeish
Eight-Time .NET MVP
VFP and iOS Author, Speaker & Trainer
Oak Leaf Enterprises, Inc.
Chief Architect, MM Framework
http://www.oakleafsd.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform