CtrlType.Assembly.CreateInstance
(1)
CtrlType.FullName
(1)
Combobox.SelectedIndex
(1)
Type.GetType
(1)
ComboBox
(1)
SelectedIndexChanged
(1)
CreateInstance
(1)
SelectedIndexChange
(1)

Dynamically load custom controls

Asked By Maanu
12-Mar-10 11:48 AM
Hi,

When the user selects an item in a combo box, I need to load the
corresponding custom control on a particular area of the form. There can be n
items in the combo box. The association between an item in the combo box and
the corresponding custom control will be kept in an xml file.

Is that possible?

What would be the steps involved in loading custom controls in this way?
Where can I get more information?

Thanks!

A quick google found: http://ilab.ahemm.org/DynamicControls.html

amdrit replied to Maanu
12-Mar-10 11:53 AM
A quick google found:  http://ilab.ahemm.org/DynamicControls.html

"Maanu" wrote:Combox_SelectedIndexChanged(){It would be the event to find out

Mr. Arnold replied to Maanu
12-Mar-10 12:03 PM
Combox_SelectedIndexChanged()
{
It would be the event to find out what was selected in the combobox by
the user.
Assuming that combobox was loaded with combox.DataValue (a key) or
getting the Combobox.SelectedIndex what item in the Combox was selected will
allow you to call this other control with information about the selction.

You're other control can be accessed in this method.

You can also get the combobox.text here too of the item selected.
}

ComboBox_SelectedIndexChange(object sender,EventArg e){ComboBox combo =

zooots replied to Maanu
12-Mar-10 12:43 PM
ComboBox_SelectedIndexChange(object sender,EventArg e)
{
ComboBox combo = (ComboBox)sender;
string CtrlTypeName = combo.SelectedValue;
Type CtrlType = Type.GetType(CtrlTypeName);
object ctrl = CtrlType.Assembly.CreateInstance(CtrlType.FullName);
InitialCustomerCtrl;
Panel.Controls.Add(ctrl);
}

zooots
Post Question To EggHeadCafe