none
How to access control on form by a string variable form and control name

    Question

  • Ok, here's what I've got:

    There is a splitter control and a tree view on my form.  When a user selects a node on the treeview node, i can retrieve from that node then name of a panel control and from the parent node the name of the form that panel control is on.

     

    I want to add that control to the other panel in my split container. 

     

    My question is how do I retrieve that control from the names of the form and the control?  

     

    For example: 

    Me.SplitContainer1.Panel2.Controls.Add(frm_01.fraE1_01_01)

     

    I want to do this but with the form name and the control name as string variables.

     

    Thanks for any help!

    Thursday, January 17, 2008 9:25 PM

Answers

  • The form can be obtained by name with:

    Application.OpenForms["formName"]; // that is to say Form.Name property, not the class name

     

    Controls are access similarily:

    form.Controls["controlName"];

     

     

    Thursday, January 17, 2008 10:30 PM

All replies

  • Normally, when I want to use strings to identify a control, I put the string in the control's tag attribute. Then I interate through the controls until I find the one that has the string that I need.

     

    Thursday, January 17, 2008 10:24 PM
  • The form can be obtained by name with:

    Application.OpenForms["formName"]; // that is to say Form.Name property, not the class name

     

    Controls are access similarily:

    form.Controls["controlName"];

     

     

    Thursday, January 17, 2008 10:30 PM