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.
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
Last edited by jmcilhinney; Sep 27th, 2012 at 04:24 AM.
2007-2013
Why is my data not saved to my database? | Communicating between multiple forms | MSDN Data Walkthroughs
MSDN "How Do I?" Videos: VB | C#
VBForums Database Development FAQ
My CodeBank Submissions: VB (*NEW* Pausing Code) | C#
My Blog: Using Parameters in ADO.NET | Keyboard Events | Assemblies & Namespaces
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.
2007-2013
Why is my data not saved to my database? | Communicating between multiple forms | MSDN Data Walkthroughs
MSDN "How Do I?" Videos: VB | C#
VBForums Database Development FAQ
My CodeBank Submissions: VB (*NEW* Pausing Code) | C#
My Blog: Using Parameters in ADO.NET | Keyboard Events | Assemblies & Namespaces
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.You can get a control by name from the Controls collection of its parent
2007-2013
Why is my data not saved to my database? | Communicating between multiple forms | MSDN Data Walkthroughs
MSDN "How Do I?" Videos: VB | C#
VBForums Database Development FAQ
My CodeBank Submissions: VB (*NEW* Pausing Code) | C#
My Blog: Using Parameters in ADO.NET | Keyboard Events | Assemblies & Namespaces