Access into a specific control by name, NO by its index.

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

In my winform application I want to change the label's text propertie.
My labels are inside a panel (pnlCalendar). I know the label's name but no the index

Me.pnlCalendar.Controls("label1").text doesn't work.

Only if I change "label1" by its integer index it works. I can search this index making a loop but I'm not interested in because I want my applications runs fast

Any idea how to access directly knowing only the name, no the index

Thanks in advance

Monts
 
* =?Utf-8?B?TW9udHNl?= said:
In my winform application I want to change the label's text propertie.
My labels are inside a panel (pnlCalendar). I know the label's name but no the index.

Me.pnlCalendar.Controls("label1").text doesn't work.

Add all controls to a 'Hashtable', use their names as keys.
 
I'm also trying to convert a text (ex. Mytext1) into a control

Mytext1 = "Me.pnlCalendar.Controls("""label1""").text

Eval method in visual basic 6.0 it would work correctly, but in visual basic .net I don't know how to do it..

Monts
 
* =?Utf-8?B?TW9udHNl?= said:
I'm also trying to convert a text (ex. Mytext1) into a control:

Mytext1 = "Me.pnlCalendar.Controls("""label1""").text"

Eval method in visual basic 6.0 it would work correctly, but in visual basic .net I don't know how to do it...

There was no eval method in VB6.
 
Hi Montse,
IMHO what Herfried suggested is the best way to do it. Don't look for any
build-in methods in the framework.. There isn't any. The controls are not
guarantied to have their Name properties set.
--
B\rgds
HTH
100 [C# MVP]

Montse said:
In my winform application I want to change the label's text propertie.
My labels are inside a panel (pnlCalendar). I know the label's name but no the index.

Me.pnlCalendar.Controls("label1").text doesn't work.

Only if I change "label1" by its integer index it works. I can search this
index making a loop but I'm not interested in because I want my applications
runs fast.
 
Back
Top