Ok my title is probably very vague and unclear.
Kind of hard to sumerise in the title.

My form has a bunch of textboxes.
The content is supposed to be saved with a button.
BUT not all the textboxes will have content in them.
So lets say i added content to the 1st textbox/selected textbox.
I want it to save just that.
All textboxes have a different name of course.
So basically a generic name for all textboxes on the form.
But without clearing content which is already present in other textboxes.

Hope i am making somewhat sense here.
Have a feeling i dont.

5 Years
Discussion Span
Last Post by Sevyt

Try this:

Private Sub btnSaveText_Click(sender As System.Object, e As System.EventArgs) Handles btnSaveText.Click
    ' assuming the form is the parent container of the textboxes
    ' otherwise use me.<container>.controls
    For Each ctrl As control In me.controls
        If TypeOf ctrl Is Textbox Then
        ' alternative check for ctrl.Name here
            If (Not(ctrl.text is nothing)) Then
            End If
        ' end ctrl.Name check
        End If
End Sub

Sub SaveText(stringIn as String)
    ' TODO: your code here to save text
    Throw New NotImplementedException
End Sub

Edited by john.knapp: code refinement


I don't have access to VB while my computer is in the shop but let me make a suggestion (you'll have to verify the syntax). You can check all of the textboxes on the form by

For Each tbx As TextBox In Me.Controls.OfType(Of TextBox)()
    If tbx.Text <> "" Then
        'process textbox with content
    End If

If some of the textboxes do not need to be checked then you can either put all the ones to check in a groupbox and just check within that group, or you could place some value in the Tag property of each textbox to check and ignore the ones without that value.

So lets say i added content to the 1st textbox/selected textbox.
I want it to save just that.

You can't check only the selected textbox because by clicking the button you deselect the textbox.

Edited by Reverend Jim

Votes + Comments
nice... much cleaner than mine

Alright another less learned.
Works the way i needed it.

Thanks guys.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.