Windows Phone Developers

Showing posts with label Add an Array to List. Show all posts
Showing posts with label Add an Array to List. Show all posts

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

Sunday, April 11, 2010

How to Add an Array to List using C# /.NET

Add Range to List using C# / .NET

Let us take our own IPL example. The current IPL has eight teams that are part of the list

            List lstIPLTeams = new List();

            lstIPLTeams.Add("Mumbai Indians");
            lstIPLTeams.Add("Chennai SuperKings");
            lstIPLTeams.Add("Kolkatta KnightRiders");
            lstIPLTeams.Add("Deccan Chargers");
            lstIPLTeams.Add("Rajastan Royals");
            lstIPLTeams.Add("Delhi DareDevils");
            lstIPLTeams.Add("KingsXI Punjab");
            lstIPLTeams.Add("RC Bangalore");




From next year two new teams- Pune and Kochi - will be part of IPL

Hence we are adding those two teams to an Array and adding the array using AddRange method

            string[] NewIPLTeams = { "Pune", "Kochi" };
            lstIPLTeams.AddRange(NewIPLTeams);

            Console.WriteLine("\nList After Add Range");
            Console.WriteLine("=======================");
            foreach (string IPL in lstIPLTeams)
            {
                Console.WriteLine(IPL.ToString());
            }


This will add Pune and Kochi to end of the list 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