Windows Phone Developers

Wednesday, September 7, 2011

How to Convert Textboxes to Array/List in VB.NET/C#

Array of Textboxes using VB.NET/C# / Loop through Textboxes in VB.NET

Here is a simple code that loops through all the controls on a Windows form and Appends the Array/List with the values

Sub GetTextBoxValues()

        Dim arTextBoxVal() As String
        Dim arTBCnt As Integer = 0
        Dim ListTB As New List(Of String)

        For Each ctlText In Me.Controls
            If TypeOf ctlText Is TextBox Then
                ReDim Preserve arTextBoxVal(arTBCnt)
                arTextBoxVal(arTBCnt) = DirectCast(ctlText, TextBox).Text
                ListTB.Add(DirectCast(ctlText, TextBox).Text)
                arTBCnt += 1
            End If
        Next

    End Sub
Digg Technorati Delicious StumbleUpon Reddit BlinkList Furl Mixx Facebook Google Bookmark Yahoo
ma.gnolia squidoo newsvine live netscape tailrank mister-wong blogmarks slashdot spurl StumbleUpon

No comments:

Post a Comment