Controls
-
-
Hi How i can get control by names: For example i have 3 textbox with name tb0,tb1,tb2 i need to fill them in loop how to do that?? for(int i=0;i<3;i++) { TextBox tb=??? } GOod bye best regards
when i want to read something good just seat and type it
Hello To get a control by name use
this.Controls["Controlname"]
, like thisfor(int i=0;i<3;i++)
{
TextBox tb= (TextBox)this.Controls["tb" + i.ToString()];
}Yet such a loop doesn't have any error checking. You must make sure that the control is a TextBox using the
is
oras
keywords. Also if your textbox is in a container -eg. GroupBox-, Then it's inside the controls of that GroupBox not the form, ie.TextBox tb= (TextBox)this.MyGroupBox.Controls["tb" + i.ToString()];
Regards:rose:
-
Hello To get a control by name use
this.Controls["Controlname"]
, like thisfor(int i=0;i<3;i++)
{
TextBox tb= (TextBox)this.Controls["tb" + i.ToString()];
}Yet such a loop doesn't have any error checking. You must make sure that the control is a TextBox using the
is
oras
keywords. Also if your textbox is in a container -eg. GroupBox-, Then it's inside the controls of that GroupBox not the form, ie.TextBox tb= (TextBox)this.MyGroupBox.Controls["tb" + i.ToString()];
Regards:rose:
-
Hello To get a control by name use
this.Controls["Controlname"]
, like thisfor(int i=0;i<3;i++)
{
TextBox tb= (TextBox)this.Controls["tb" + i.ToString()];
}Yet such a loop doesn't have any error checking. You must make sure that the control is a TextBox using the
is
oras
keywords. Also if your textbox is in a container -eg. GroupBox-, Then it's inside the controls of that GroupBox not the form, ie.TextBox tb= (TextBox)this.MyGroupBox.Controls["tb" + i.ToString()];
Regards:rose:
//if controls are on form foreach(Control c in this.Controls) { if(c is textbox) c.Text = "some text"; } //if controls are in some container foreach(Control c in this.ContainerName.Controls) { if(c is textbox) c.Text = "some text"; } i hope it works
ihtesham
-
//if controls are on form foreach(Control c in this.Controls) { if(c is textbox) c.Text = "some text"; } //if controls are in some container foreach(Control c in this.ContainerName.Controls) { if(c is textbox) c.Text = "some text"; } i hope it works
ihtesham
Gee!! Thanks for your reply!:laugh: Only one problem is that it wasn't me who asked the question!!;P He won't get a notification of your reply if you replied to me. Repost your reply by replying to his original post.
Regards:rose: