473,387 Members | 1,669 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Seeking better way to load user controls in form

I'm developing a Windows application that will have an ListBar like in
Outlook. When the user clicks on a ListBar item, I would like to load the
associated User Control. The below code works fine, but I'm looking for
something more dynamic (since we'll have dozens if not hundreds of user
listbar items/user controls).

private void ulbListBar_ItemSelected(object sender,
Infragistics.Win.UltraWinListBar.ItemEventArgs e)
{
splContainer.Panel2.Controls.Clear();

switch (e.Item.Key)
{
case "keyTesting_CountryList":
uctTesting_CountryList _uctTesting_CountryList = new
uctTesting_CountryList();
splContainer.Panel2.Controls.Add(_uctTesting_Count ryList);
break;

case "keyTesting_StateList":
uctTesting_StateList _uctTesting_StateList = new
uctTesting_StateList();
splContainer.Panel2.Controls.Add(_uctTesting_State List);
break;
}
}

Thanks for any suggestions.
Ron
Mar 19 '07 #1
3 1974
Ronald,

Well, most, if not all controls have a parameterless public constructor.
Combine that with the fact that you know all the controls are going to be
passed to the Add method on the controls collection exposed by the Controls
property on the Panel2 control, and you can easily use reflection (along
with a dictionary or some other lookup mechanism to determine the type to
create) to create the instance and add it to the panel.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Ronald S. Cook" <rc***@westinis.comwrote in message
news:uU**************@TK2MSFTNGP04.phx.gbl...
I'm developing a Windows application that will have an ListBar like in
Outlook. When the user clicks on a ListBar item, I would like to load the
associated User Control. The below code works fine, but I'm looking for
something more dynamic (since we'll have dozens if not hundreds of user
listbar items/user controls).

private void ulbListBar_ItemSelected(object sender,
Infragistics.Win.UltraWinListBar.ItemEventArgs e)
{
splContainer.Panel2.Controls.Clear();

switch (e.Item.Key)
{
case "keyTesting_CountryList":
uctTesting_CountryList _uctTesting_CountryList = new
uctTesting_CountryList();
splContainer.Panel2.Controls.Add(_uctTesting_Count ryList);
break;

case "keyTesting_StateList":
uctTesting_StateList _uctTesting_StateList = new
uctTesting_StateList();
splContainer.Panel2.Controls.Add(_uctTesting_State List);
break;
}
}

Thanks for any suggestions.
Ron


Mar 19 '07 #2
Hi,

All your list should inherite a same baseclass,and the main form only deal
with
the base calss.

Your sub-class,uctTesting_CountryList..,should be created by a
xxxFactory,then
added into a list in main-form.

Main-form control the 'list' using abstract interace,and 'list' do all the
concrete things.

gshzheng
20070320
"Ronald S. Cook" <rc***@westinis.comдÈëÏûÏ¢ÐÂÎÅ:uU**************@T K2MSFTNGP04.phx.gbl...
I'm developing a Windows application that will have an ListBar like in
Outlook. When the user clicks on a ListBar item, I would like to load the
associated User Control. The below code works fine, but I'm looking for
something more dynamic (since we'll have dozens if not hundreds of user
listbar items/user controls).

private void ulbListBar_ItemSelected(object sender,
Infragistics.Win.UltraWinListBar.ItemEventArgs e)
{
splContainer.Panel2.Controls.Clear();

switch (e.Item.Key)
{
case "keyTesting_CountryList":
uctTesting_CountryList _uctTesting_CountryList = new
uctTesting_CountryList();
splContainer.Panel2.Controls.Add(_uctTesting_Count ryList);
break;

case "keyTesting_StateList":
uctTesting_StateList _uctTesting_StateList = new
uctTesting_StateList();
splContainer.Panel2.Controls.Add(_uctTesting_State List);
break;
}
}

Thanks for any suggestions.
Ron

Mar 20 '07 #3
Thanks Nicholas.. any chance you'd have a code snippet to throw my way?

Thanks,
Ron
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.comwrote in
message news:uu**************@TK2MSFTNGP05.phx.gbl...
Ronald,

Well, most, if not all controls have a parameterless public
constructor. Combine that with the fact that you know all the controls are
going to be passed to the Add method on the controls collection exposed by
the Controls property on the Panel2 control, and you can easily use
reflection (along with a dictionary or some other lookup mechanism to
determine the type to create) to create the instance and add it to the
panel.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Ronald S. Cook" <rc***@westinis.comwrote in message
news:uU**************@TK2MSFTNGP04.phx.gbl...
>I'm developing a Windows application that will have an ListBar like in
Outlook. When the user clicks on a ListBar item, I would like to load
the associated User Control. The below code works fine, but I'm looking
for something more dynamic (since we'll have dozens if not hundreds of
user listbar items/user controls).

private void ulbListBar_ItemSelected(object sender,
Infragistics.Win.UltraWinListBar.ItemEventArgs e)
{
splContainer.Panel2.Controls.Clear();

switch (e.Item.Key)
{
case "keyTesting_CountryList":
uctTesting_CountryList _uctTesting_CountryList = new
uctTesting_CountryList();
splContainer.Panel2.Controls.Add(_uctTesting_Count ryList);
break;

case "keyTesting_StateList":
uctTesting_StateList _uctTesting_StateList = new
uctTesting_StateList();
splContainer.Panel2.Controls.Add(_uctTesting_State List);
break;
}
}

Thanks for any suggestions.
Ron



Mar 20 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Jeremy | last post by:
Everything in my app worked fine - then I moved some user controls to a subfolder named \ControlTemplates that physically exists directly under the site root. Then, at runtime when these lines...
2
by: Sam Kuehn | last post by:
There has been a lot of articles on how to load user controls at runtime in the Init() method. UserControl myControl = (UserControl)LoadControl(stringControl); I add the control in the Init()...
2
by: guoqi zheng | last post by:
Dear Sir, I have a menu page (main.aspx") with a placeholder on it. This placeholder will load a a main menu item user controls (mainmenu.ascx), on this page, there are a few menu items, When...
6
by: Ronald S. Cook | last post by:
We have a Windows app that has one main form (a shell, sort of). We then load user controls into a panel on the form depending on what the user has selected. Our current code to unload the...
3
by: Ronald S. Cook | last post by:
I lost my last post, but I'm looking for a better way to manage loading user controls (that are essentially forms) in a Windows app. In my current design, I have a ListBar in which the user...
0
abehm
by: abehm | last post by:
I have a couple placeholders in which I want to dynamically load user controls into a multi-pageview based on db data. The database returns the filename of the user control (i.e....
0
by: joeller | last post by:
I need to dynamically load controls and access the methods and property of the control from the page. I need to load a different control depending on a selection made by the user. I have buttons on...
1
by: Christian Resma Helle | last post by:
Hey guys, I'm working on an AJAX Enabled ASP.NET Web application. I have a TreeView web control and an PlaceHolder web control. My PlaceHolder is inside an UpdatePanel and AsyncPostBacks are...
18
CroCrew
by: CroCrew | last post by:
Hello all, Thanks for looking at my post and thank to anyone that provides me with the help I am looking for. I dynamically load user controls from a default page but when a postback fires...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.