tags:

views:

208

answers:

2

I have a variable of type UserControl private at the top of a class.

Depending of some condition, one of my two UserControl is displayed. The problem is that I wanted to SET the global private variable of type UserControl to the visible UserControl to have a reference on it for later use. I always got Error Type Mismatch.

Private mo_SelectedControl As UserControl
'...
'...Some where in a Sub:
set SelectedControl = myUserControl

I have try with myUserControl.object, and it doesn't work neither. Any idea?

+2  A: 

Try declaring your variable as type Control instead of UserControl.

Christian Hayter
In which case you may as well use object. ;)
AnthonyWJones
A: 

Just for your info UserControl is quite confusing. UserControl is the interface that VB code (from inside the control) uses to interact with the site in which it is placed.

Access to the UserControl interface is performed via the UserControl keyword. This interface is not inherited by the final implementation hence the actual exposed public interface of the control consists entirely of whatever you choose to make public.

The actual object created by VB when an instance of the control is added to the Form is a COM aggregate of an object used to site the control (the one that carries the Left and Top properties for example) and the public part of the user control. Unfortunately the interface actually aggregated is not UserControl despite it sharing a number of members in common.

Hence you can't assign an instance of a "UserControl" to a variable of type UserControl. I think somewhere someone dropped the ball on that one.

AnthonyWJones