Windows Phone Developers

Wednesday, April 21, 2010

How to Add Generic List Items to ListBox in C# / VB.NET

We have already seen How to Add an ArrayList to ListBox. The following code shows how to add a C# Generic List to ListBox


        public void Load_LB_GenericList()
        {
            List Team = new List();
            ClassTeam CT = new ClassTeam(ClassTeam.playerType.Contract, "Sachin", 23, "33420242");
            Team.Add(CT);
            CT = new ClassTeam(ClassTeam.playerType.Contract, "Sourav", 23, "33420242");
            Team.Add(CT);
            CT = new ClassTeam(ClassTeam.playerType.Contract, "Dravid", 23, "33420242");

            Team.Add(CT);
            listBox1.DataSource = Team;
            listBox1.DisplayMember = "Name";
            listBox1.ValueMember = "Phone";

        }
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

1 comment: