Need help working with form objects

mebner

New member
Joined
Apr 8, 2005
Messages
1
Location
Chicago
Programming Experience
3-5
Hello!


I am having trouble with the syntax I should use to allow a method to 'walk' through all the controls on a particular form. Each form I would use this on could have groupboxes, tab controls, listbox, panels, textboxes, labels, combo, etc... It would have to be iterative in order to find the textboxes & comboboxes.

If a group control is found (aka groupbox, tabcontrol, etc,...) I would then need to check its children as well until I found a textbox or combobox. I am not concerned with labels at this point. Once the lowest level is found I want to perform an operation on that control & need to know the name of the control.

This is what I have so far, but I get an error when I check the subObj:

I believe in order to dim the grpbox control I need to know its name at that point. Also, I am not getting the desired results when dealing with the object.

Any thoughts or pointers are appreciated.
Dim obj AsObject

Dim shop AsNew ShopControl

Dim str AsString

Dim GrpObj As GroupBox

ForEach obj In shop.Controls

If (obj.GetType).ToString = "System.Windows.Forms.TextBox" Then

str = sender.GetType.FullName

ElseIf (obj.GetType).ToString = "System.Windows.Forms.GroupBox" Then

'str = sender.GetType.FullName 'Customer.ShopControl

str = obj.GetType.Name 'Groupbox

'Dim subObj As System.Windows.Forms.GroupBox.ControlCollection

Dim subObj AsObject

ForEach subObj In obj

If (obj.GetType).ToString = "System.Windows.Forms.TextBox" Then

str = sender.GetType.FullName

ElseIf (obj.GetType).ToString = "System.Windows.Forms.GroupBox" Then

'str = sender.GetType.FullName 'Customer.ShopControl

str = subObj.GetType.Name 'Groupbox

ElseIf (obj.GetType).ToString = "System.Windows.Forms.TabControl" Then

str = sender.GetType.FullName

EndIf

Next



ElseIf (obj.GetType).ToString = "System.Windows.Forms.TabControl" Then

str = sender.GetType.FullName

EndIf

Next

thanks,

Mike
 
Back
Top