Hi,
How can I dynamically find all of the linklabel within a form, then get the linklabel name?

thanks for this one dude,.but when i tried that and it didn't work..it seems that it didn't fit to what i want to happen.

here's the scenario..'

http://www.daniweb.com/software-development/vbnet/threads/378064

you'd already answered there my question about searching the label's name within the form.

now, what i want is, when my form loads,.it will detect each label's name..for example(ex. of my label's name lbl23WS001).,then it will compare the label's name to my database if it exist..if it exist in the database, it will then change it's backcolor. :)

Are all the LinkLabels on the Form or are they in separate containers as Panels?
If in separate containers, then you need to loop thruough each container's controls, not thruough the Form's controls. A simple Sub with a Parameter should do this just nicely.

If you still have issues with this, post the code that you have so far.

Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Dim StackOfControls As New Stack(Of Control)
        Dim AllLinkLabels As New List(Of LinkLabel)
        Dim ControlChecking As Control

        StackOfControls.Push(Me)
        Do While StackOfControls.Count > 0
            ControlChecking = StackOfControls.Pop
            For Each ChildControl As Control In ControlChecking.Controls
                If TypeOf ChildControl Is LinkLabel Then
                    AllLinkLabels.Add(ChildControl)
                End If
                If ChildControl.Controls.Count > 0 Then
                    StackOfControls.Push(ChildControl)
                End If
            Next
        Loop

        'All link labels inside AllLinkLabels
        'Iterate through the list and get the name
    End Sub
Comments
impressive :)
This article has been dead for over six months. Start a new discussion instead.