Avatar of posseke
posseke
Flag for Cabo Verde asked on

Loop through Form Controls

Hi,

I've been working on a recursive method that loops through every single control in a form, and enables/disables it if needed.
The problem I am having is that I want to disable certain buttons on the BindingNavigator, but none of them are present in the control collection of the BindingNavigator. Is anyone aware of this situation, or do I need to adapt my code? (see below)

The method below searches for a certain control , given its name ('keyword' parameter), starting in a certain topLevelControl (i.e the main form)
It returns true if the control was found, and false if otherwise.

But when i debug the code I can clearly see that the BindingNavigator control contains no subchild controls, even though there are buttons and textboxes on the BindingNavigator.

[CODE]

    Private Function findControlByKey(ByVal topLevelControl As Control, ByVal keyWord As String) As Boolean
        '
        For Each subControl As Control In topLevelControl.Controls
            '
            If subControl.HasChildren = True Then
                '
                If findControlByKey(subControl, keyWord) = True Then
                    Return True
                End If
                '
            Else
                '
                If subControl.Name = keyWord Then
                    '
                    Return True
                    '
                End If
                '
            End If
            '
        Next
        '
        Return False
        '
    End Function

[/CODE]


Any help or suggestions as to approach this in a different manner is greatly appreciated!

Yours truly,

Po$$e

 
Visual Basic.NET

Avatar of undefined
Last Comment
posseke

8/22/2022 - Mon
gladiatorno9

posseke

ASKER
gladiatorn09,

Thx for the URL's, but i have allready viewed them, and I know how to recursively loop through the control collections...
The problem is that the BindingNavigator shows no controls in its collection, but there are buttons present on it (i.e save button, delete button,...)

So, I can allready loop through every single control, no help needed for that, just want to know why or how I can access BindingNavigator controls.

Greets,

Po$$e
ASKER CERTIFIED SOLUTION
DjDezmond

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
posseke

ASKER
DjDezmond,

I'm really having an embarrassed moment you know, why didn't I come up with that? Seems to me i was to focused on the Control Collection.
But now I understand why the BindingNavigator buttons aren't visible when you use

BindingNavigator.Controls("myControl").Enabled


They are all ToolstripItems contained in the Item Collection of the BindingNavigator

Thx for helping me out and making me feel so tiny :p
I would say; easy but well earned 400 points for you my rriend!!!

Greetz,

Po$$e
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
DjDezmond

... sorry, its actually not what you wanted. You can swap the .Enabled for .Name and use that to return true or false, but it still leaves the Navigator control out of the TopLevelControl.Controls set.

You can use subControl.Controls.Items("KeyName") but you'd have to alter the code so it knows it can look through the item list.

I got a Null Exception error whilst trying to play with it, but i just put that down to me not binding anything to the controls so nothing was enabled.

Dez
DjDezmond

OK, didn't realise you'd posted again already lol.

I didn't think that was what you needed for the looping sub above... but at least its got you back on the right track...

Thanks for the points :p

Dez
posseke

ASKER
No problem :)

Greets,

Po$$e
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.