|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Setting an object to a UserControlthat User Control? ie; I have a User Control, called "Accounts" in my project I tried the following code strUserControlName = "Accounts" frmMain.Controls.Add(strUserControlName) But, of course, the above code doesn't work, because the second line of code wants a User Control parameter, not a string parameter. so, I need to do something like this: dim objUserControl as UserControl set objUserControl = UserControl(strUserControlName) How do I do this? Your help would be appreciated. Dave
Show quote
Hide quote
"Dave" <D***@discussions.microsoft.com> schrieb: Check out the code snippets at > If I have a name of a User Control in my project, how can I set an Object > to > that User Control? > > ie; > > I have a User Control, called "Accounts" in my project > I tried the following code > > strUserControlName = "Accounts" > frmMain.Controls.Add(strUserControlName) > > But, of course, the above code doesn't work, because the second line of > code > wants a User Control parameter, not a string parameter. <URL:http://dotnet.mvps.org/dotnet/code/techniques/#ClassByName>. -- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://classicvb.org/petition/>
Show quote
Hide quote
"Herfried K. Wagner [MVP]" wrote: I don't think that answers my question, at least as far as I can tell, not > "Dave" <D***@discussions.microsoft.com> schrieb: > > If I have a name of a User Control in my project, how can I set an Object > > to > > that User Control? > > > > ie; > > > > I have a User Control, called "Accounts" in my project > > I tried the following code > > > > strUserControlName = "Accounts" > > frmMain.Controls.Add(strUserControlName) > > > > But, of course, the above code doesn't work, because the second line of > > code > > wants a User Control parameter, not a string parameter. > > Check out the code snippets at > <URL:http://dotnet.mvps.org/dotnet/code/techniques/#ClassByName>. > > -- > M S Herfried K. Wagner > M V P <URL:http://dotnet.mvps.org/> > V B <URL:http://classicvb.org/petition/> > > Herfried; being able to read German. The examples on your page seem to be detailing creating new objects. I've already got the UserControls created. They are in my project already. I need to pick one, based on a user request, add it to the controls in my current form and display the form. I've already got ucAccounts.vb, ucInventory.vb, ucOrders.vb if the user picks "Accounts" from a list, I need to add the ucAccounts to my form, and display that User Control. So, I need something like Select Case UserSelection case "Accounts" frmMain.Controls.Add(ucAccounts) case "Inventory" frmMain.Controls.Add(ucInventory) case "Orders" frmMain.Controls.Add(ucOrder) End Select But, because I've got about 30 User Controls, and the number will be growing, I'd really rather do it elegantly, rather than with a gigantic Select statement.
Show quote
Hide quote
"Dave" <D***@discussions.microsoft.com> schrieb In the project, you've created classes, not objects. If you want to> > > "Herfried K. Wagner [MVP]" wrote: > > > "Dave" <D***@discussions.microsoft.com> schrieb: > > > If I have a name of a User Control in my project, how can I set > > > an Object to > > > that User Control? > > > > > > ie; > > > > > > I have a User Control, called "Accounts" in my project > > > I tried the following code > > > > > > strUserControlName = "Accounts" > > > frmMain.Controls.Add(strUserControlName) > > > > > > But, of course, the above code doesn't work, because the second > > > line of code > > > wants a User Control parameter, not a string parameter. > > > > Check out the code snippets at > > <URL:http://dotnet.mvps.org/dotnet/code/techniques/#ClassByName>. > > > > > > > Herfried; > I don't think that answers my question, at least as far as I can > tell, not being able to read German. The examples on your page seem > to be detailing creating new objects. > > I've already got the UserControls created. They are in my project > already. I need to pick one, based on a user request, add it to the > controls in my current form and display the form. create an object by it's class name, Herfried's link is the way to go. Show quoteHide quote > I've already got ucAccounts.vb, ucInventory.vb, ucOrders.vb See Herfried's link. It creates a new object based on the class name.> if the user picks "Accounts" from a list, I need to add the > ucAccounts to my form, and display that User Control. > > So, I need something like > > Select Case UserSelection > case "Accounts" > frmMain.Controls.Add(ucAccounts) > case "Inventory" > frmMain.Controls.Add(ucInventory) > case "Orders" > frmMain.Controls.Add(ucOrder) > End Select > > But, because I've got about 30 User Controls, and the number will be > growing, I'd really rather do it elegantly, rather than with a > gigantic Select statement. Armin |
|||||||||||||||||||||||