CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    May 2003
    Posts
    42

    Exclamation Adding User Control

    Hi,

    I am trying to add my user control into the toolbox then onto my form. Every time I try it tells me it cannot create an instance of the control, one of the controls dependancies could not be found.

    Any ideas?

  2. #2
    Join Date
    Jun 2005
    Location
    Maryland,USA
    Posts
    20

    Re: Adding User Control

    what kind of a user control is it?is it a web user control(ascx) or a windows user control?

  3. #3
    Join Date
    May 2003
    Posts
    42

    Re: Adding User Control

    It is a Windows control...it basically says a library I reference inside the control isn't compiled or something, but it is fine...

  4. #4
    Join Date
    Feb 2005
    Location
    Israel
    Posts
    1,475

    Re: Adding User Control

    The Toolbox is somewhat weak in VS.NET 2003.
    This thing can happen because of many reasons: run-time bug in the constuctor of the user control, reference that is not in the correct location, and so on.

    I suggest to do the following steps:
    1. Add the reference to the library with control ourself.
    2. Add the control by code (not from the designer):
    Code:
    YourUserControl uc = new YourUserControl();
    3. put a breakpoint on that line of code. Step into the constructor of the control and try to find bugs.

  5. #5
    Join Date
    May 2003
    Posts
    42

    Re: Adding User Control

    Well that is the weird thing...I added the control by hand previously after I got this error and I haven't found any bugs yet...

  6. #6
    Join Date
    Jun 2004
    Location
    Kashmir, India
    Posts
    6,808

    Re: Adding User Control

    Well before using the user control there are few things which you should take care of..

    1. If you are developing the User Control in the same project, then before using it you need to build the project first.
    2. If you have the user control in the separate project, make sure that you have added the reference to that assembly prior to using it.
    3. There is no need to add a user control to the Toolbox, it will automatically be added under My User Controls tab once you build your project.
    4. If you do any change in the source of your user control, make sure you re-build the porject and then use a new instance of the user_control..

    HTH

  7. #7
    Join Date
    May 2003
    Posts
    42

    Re: Adding User Control

    Yes I have the control in the same project as the form I am dropping it on.

    I build the project before the attempt - but my user controls are never added automatically to the 'My User Controls' part of the toolbox??

    All the references are fine I am positive of that - I add other user controls just fine the same way but this one won't let me do it. I can add it programmatically and use it but then if I make a change to the form it disappears on me.

  8. #8
    Join Date
    May 2003
    Posts
    42

    Re: Adding User Control

    I got the control added...the suggestion about cleaning up the constructor helped...thanks for all your suggestions!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured