Click here to Skip to main content
15,888,026 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Form1:

public string labelText
{
get{
return Label1.text;
}
set{
Label1.text=value;
}
}

Form2:

(Form) frm=new Form("Form1");
frm.findcontrol(dt.Rows[0]["ControlName"].toString()).text=dt.Rows[0]["ChangeText"].toString();

Above winForm code is not working. And Form1 and Form2 are inside the folder(Window Forms)

What I have tried:

I have Dynamic Form name and label name. My main issue is I want change the label name dynamically.
Posted
Updated 20-Mar-16 9:10am
Comments
Sascha Lefèvre 20-Mar-16 8:17am    
"not working" generally isn't a good explanation of a problem. Do you get an exception? Or is simply nothing happening?
Richard MacCutchan 20-Mar-16 9:19am    
frm.findcontrol(dt.Rows[0]["ControlName"].toString()).text=dt.Rows[0]["ChangeText"].toString();
Statements like that are often the cause of problems.

Also, where exactly is this code executed? If it is in some method of Form2 then it is never going to work.
RickZeeland 25-Mar-16 14:02pm    
And ? did you try my solution, or have you given up ?

1 solution

You could use something like this:

C#
foreach (System.Windows.Forms.Control ctrl in frm.Controls)
{
    switch (ctrl.GetType().Name)
    {
        case "Button":
        case "ToolStrip":
        case "ToolStripMenuItem":
        case "DataGridView":
            Debug.Print(ctrl.Name);
            break;
        default:
            break;
    }
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900