Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET
http://uploadpic.org/storage/2011/bEJhbXzf8ijl3jY0wipzFkQn5.png[^]
 
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 5:22am

1 solution

Rate this: bad
good
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 | :)
  Permalink  
v2
Comments
Ahmed.ganainy at 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 at 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 at 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 at 8-Feb-13 13:08pm
   
see updated solution
Ahmed.ganainy at 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 at 8-Feb-13 13:20pm
   
i forgot to appreciate your interest and fast respond..
Aarti Meswania at 8-Feb-13 13:22pm
   
welcome! :)
Glad to help you! :)
Aarti Meswania at 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
0 OriginalGriff 6,649
1 Sergey Alexandrovich Kryukov 6,270
2 CPallini 5,190
3 George Jonsson 3,574
4 Gihan Liyanage 2,522


Advertise | Privacy | Mobile
Web01 | 2.8.140916.1 | Last Updated 8 Feb 2013
Copyright © CodeProject, 1999-2014
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