Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cycling through forms 1

Status
Not open for further replies.

artyk

Programmer
Apr 5, 2006
163
US
Hi,all. I'm developing an app that needs to add/remove controls on the fly to accomodate additional records. I added a numerical identifier to the "tag" property so that I could identify how many records there are, but I'm not sure how to cycle through the controls to find the highest "tag" value.

Basically, I need to search the form and get the control with the highest "tag" so I will know ho many controls need to be added/removed from the form.

Any assistance would be greatly appreciated.
 
Here's an example.

Code:
    Private HighestTag As Integer = 0
    Private HighestControl As Control
    Private Sub FindHighestTag(ByVal ctl As Control)
        For Each c As Control In ctl.Controls
            Try
                If Convert.ToInt32(c.Tag) > Me.HighestTag Then
                    Me.HighestTag = Convert.ToInt32(c.Tag)
                    Me.HighestControl = c
                End If
            Catch ex As Exception

            End Try
            FindHighestTag(c)
        Next
    End Sub

Test it by calling the following:
Code:
        FindHighestTag(Me)
        MessageBox.Show("Highest Control = " + HighestControl.Name + " with Tag of " + HighestTag.ToString)
 
Thanks. I'll work with it and configure it for my code and see what happens. Thanks again for your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top