Hello,
That's what i need in brevity.Code:int i;
i = 5;
lblName + i .text = "Test";
Plz help me to solve this issue.
Thanks in advance.
Printable View
Hello,
That's what i need in brevity.Code:int i;
i = 5;
lblName + i .text = "Test";
Plz help me to solve this issue.
Thanks in advance.
You can get a control by name from the Controls collection of its parent, e.g.The item is returned as a Control reference, so if you're just using members of the Control class, e.g. Text, then that's fine. If you want to access a member of that specific type of control then you should cast as that type. Indeed, if you have Option Strict On, as you should, then you will be required to cast.vb.net Code:
For i = 1 To 5 Controls("Label" & i).Text = "Label" & i Next
Thank you, I tried make code:
[Code]
int i = 1;
Controls["lblFP" + i].Text = "Test";
[Code/]
Give me error "Object reference not set to an instance of an object." i try adjust code to run but need help.
Ah whoops, I forgot I was C# land and posted VB code. It seems that you successfully translated it though. As for the error message, that means that there is no control on your form with that Name.
Hi,
I catch where is the problem, i am using groupbox this code can't find any object on groupbox must put the label on form direct and use it.
Do there any idea to surmount this problem?
Please read what I posted.If the GroupBox is the parent of the Label then you have to use the Controls collection of the GroupBox, not the form. This is exactly why I prefer not to post code: people just copy the code and don't actually read.Quote:
You can get a control by name from the Controls collection of its parent