Click here to Skip to main content
11,934,783 members (52,247 online)
Rate this:
Please Sign up or sign in to vote.
See more: VB VB.NET[^]

above is control arrays created in runtime but how can i make the user when unchecked the checkbox it will disable the text box in left hand side considering that i made the same index for checkbox() array and textbox() array.
usualy i was using direct cast so i can dynamically point to the control i need but here i can't point to control inside control array with the below
Dim c As TextBox = DirectCast(Controls("textbox(5)"), TextBox)

FYI: i want to use direct cast because i have a lot of tabs and each has check box and text boxes so using direct cast and by identifying the sender container (group panel) i can defined the location of check box and the needed part to be disabled.

another question:
when i add a handler to control array always the name properties is "" and other properties have correct values.
Posted 8-Feb-13 6:22am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

do code like below,
Dim Container As Panel = DirectCast(sender.parent,Panel ) 
if block= "Motor" then
      Dim tag As TextBox = DirectCast(Container.Controls.find(MotorTag(index),true).GetValue(0), TextBox)
else if block= "valve" then
     Dim tag As TextBox = DirectCast(Container.Controls.find(ValveTag(index),true).GetValue(0), TextBox)
end if 
Happy Coding!
Smile | :)
Ahmed.ganainy 8-Feb-13 12:31pm
In my application i have group panels and each has set of control arrays and the naming i referenced by the grouppanel name so
i want when the user click in check box i will detect the grouppanel (parent container) so i can know which text box to disable.

so i want to use something dynamic like the below

Dim Container As Panel = DirectCast(sender.parent,Panel )
Dim tag As TextBox = DirectCast(Container.Controls(block + "Tag(" + index.ToString + ")"), TextBox).

so the issue how can i directcast a control from string and using controls("controls name as string") is not working in the case of the string is tag(5)..
Aarti Meswania 8-Feb-13 12:37pm
okay from string you want do this.

then search your control by name and then cast it

tell me what is "block" in second line?
Ahmed.ganainy 8-Feb-13 13:04pm
Ahmed.ganainy - 10 mins ago
my panels names are MotorPanel, valvePanel, ScalPanel......etc
my checkboxes array are MotorCheckboxes(), valveCheckboxes()....etc
My textbox arrays are MotorTag(), valveTag().....etc

block is Motor, valve Scal....etc depend on the panel
Aarti Meswania 8-Feb-13 13:08pm
see updated solution
Ahmed.ganainy 8-Feb-13 13:19pm
yes this what i'm using "select case". but there is no way to use something like the below:
Dim tag As TextBox = DirectCast(Container.Controls(block + "Tag(" + index.ToString + ")"), TextBox).
controls("control from string") is not supporting the string to be element of array.?
Ahmed.ganainy 8-Feb-13 13:20pm
i forgot to appreciate your interest and fast respond..
Aarti Meswania 8-Feb-13 13:22pm
welcome! :)
Glad to help you! :)
Aarti Meswania 8-Feb-13 13:21pm
no you have to write array name
and see the difference..
I have underlined portion of code which uses
Find method to find control from string

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web03 | 2.8.151126.1 | Last Updated 8 Feb 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100