Link to home
Start Free TrialLog in
Avatar of Natavia Finnie
Natavia FinnieFlag for United States of America

asked on

vb.net How save and Load all textbox data on form to to a file

I am trying to save the values from textboxes and other controls recursively when my form has:
(1) tabcontrols with multiple tabPages
(2) on each tabPage are:
                   (a) several groupboxes, within a GroupBox
                   (b) panels, textboxes, and combboxes on the several groupboxes

I would like to use a similar method below but I don't get all the textboxes

For Each controlType As Control In Me.Controls
                    If TypeOf controlType Is TabControl Then
                        For Each tabpage As Control In controlType.Controls
                            If TypeOf controlType Is GroupBox Then
                                For Each txtBox As Control In controlType.Controls
                                    If TypeOf txtBox Is TextBox Then
                                        outputFile.wplWriteLine(txtBox.Name, Trim(txtBox.Text))
                                    End If
                                Next
                            End If
                        Next
                    End If
                Next
ASKER CERTIFIED SOLUTION
Avatar of Éric Moreau
Éric Moreau
Flag of Canada 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
SOLUTION
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
Or you could do what Eric recommended.

@Eric - I was not aware of that method.  ;)

-saige-
SOLUTION
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
Be aware that GetNextControl() only returns controls that have TabStop set to True (which it normally is for TextBoxes, though it could be turned off for whatever reason).
Avatar of Natavia Finnie

ASKER

@Mike Tomlinson,
The GetNextControl() works great at this point. But you say if TabStop was set to false that the function would not work? I assume the function you have include does work if TabStop is, some how, set to false?!?!
Correct, his implementation does not look at the TabStop to determine if the control is returned (although it could).

-saige-
You'd only change TabStop to False if you don't want that Control to be visited when the user hits the Tab key.  That's not normally the case for a TextBox, but it is possible.  Just wanted to make you aware of that caveat.