Link to home
Start Free TrialLog in
Avatar of posseke
possekeFlag 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

 
Avatar of gladiatorno9
gladiatorno9

Avatar of 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
Avatar of DjDezmond
DjDezmond
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of 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
... 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
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
Avatar of posseke

ASKER

No problem :)

Greets,

Po$$e