Click here to Skip to main content
15,943,210 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:[^]

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.

1 solution

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!
Share this answer
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.?

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

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900