• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 205
  • Last Modified:

Best way to 'search' controls on a panel

I have a form's tab that displays a table.
In that table, I will have x number of rows.
On each row, I'll have a checkbox, and two combos.  The names of each are very similar but unique to any additional rows.

I now have my code displaying these and functioning the way I want, so it's time to take the data there and drop it into a database.

My problem: determining the best way to get at those controls and the data the contain...
I have two ideas so far, but wanted to know the more efficient route to take.
   Loop through all controls on the panel? (I will have a class-level counter variable to determine how many rows)
   Setup a 'hidden' control that would hold the primary name (that all 3 controls in a row are based off of)
   Or, some other ingenious method? :^)
   
0
sirbounty
Asked:
sirbounty
  • 3
  • 3
1 Solution
 
sirbountyAuthor Commented:
This is the approach I have taken so far, and it seems adequate, so I'm just looking for confirmation from those more versed in .Net that I'm using the right approach...
If I can get the checkbox name, then I will have the two combo's names.
For Each ctl As Control In tlpAppts.Controls
  If TypeOf (ctl) Is CheckBox Then
  

Open in new window

0
 
Jaime OlivaresCommented:
The code snippet you posted is correct and the usual solution, but notice some controls are inside other controls. By example your panel can contain a GroupControl that contains many controls. In that case you will need an extra nested For..Each loop.
0
 
sirbountyAuthor Commented:
In this case, it's just the run-time created table.  Besides the checkbox and combos, I'll have two buttons, and that'll be it.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
Jaime OlivaresCommented:
To extend my comment:
For Each ctl As Control In tlpAppts.Controls
        If TypeOf (ctl) Is GroupBox Then
              For Each ctl1 As Control In ctl.Controls
                     If TypeOf (ctl1) Is CheckBx Then
                       ' call function to process control
                     End If
              End For
        End If
End For

Open in new window

0
 
Jaime OlivaresCommented:
Then the code snippet you posted is OK
0
 
sirbountyAuthor Commented:
Easy 250 for you then mate.
Thanx again for the help! :^)
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now