Build Custom Control Array

Hi Experts,

I have added a panel onto a form and added labels and buttons on the panel.

While loading the form, I fetch array of objects from my web service and based on the response, I would like to create an array of the custom panel I had created in design time.

How to create a custom control array of this panel, so that I automatically get an instance of all labels and buttons within the declared panel.

Suppose, the custom panel I built in design time is "pnlUserList". I would like to create an array of this panel.

Please help as soon as possible.

Regards,
Suman



Answer this question

Build Custom Control Array

  • FSOR

    Hi Suman

    This codeproject article may do what you want: http://www.codeproject.com/cs/miscctrl/ControlCloneTst.asp

    This sample may not work on .NET CF. In This case you can do something linke this:

    foreach (Control ctrl in panel.Controls)
    {
       //use reflection to find out corrent type
      // Create an new instance of the control and copy all properties
    }

    Michael



  • narasiman_jayachandran_2b5374

    I am not sure I understand your question. You're saying you want to get access to the Panel's controls Just use the pnlUserList.Controls.

    -Alex


  • Alexan

    This is what I want:
    In runtime, I want to duplicate a panel which is already created in design time, so that I can make sure the new panels are the instances of the panel created in design time and contains all the controls within it, which I pasted onto it.


  • Build Custom Control Array