Yaz  Font K   lt Yaz  Font B y lt

dataGridView da List Metodu Kullanımı Örneği

 

Merhaba arkadaşlar bu makalemizde datagridview da list metodu ile verilerin gösterimini sağlayacağız.  

 

 

Resim1


Şekil 1

 


Form1.cs

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.Windows.Forms;

 

namespace datagridview_list

{

    public partial class Form1 : Form

    {

        public Form1()

        {

             InitializeComponent();

        }

 

        class staff

        {

            public string Id { getset; }

            public string FirstName { getset; }

            public string LastName { getset; }

            public string Contact { getset; }

            public string Mail { getset; }

            public string Gender { getset; }

            public string Department { getset; }

            public string Address { getset; }

            public string PostalCode { getset; }

            public string City { getset; }

            public string State { getset; }

            public string Country { getset; }

        }

 

        List<staff> persons;

        private void btnShow_Click(object sender, EventArgs e)

        {

            persons = new List<staff>();

            persons.Add(new staff() { Id = "1", FirstName = "Bahadir", LastName = "Sahin", Contact = "+1 (212) 221-4937"

                Mail = "basahin@hotmail.com", Gender="M",Department="IT",Address= "627 Broadway",PostalCode= "10012-2612",City= "New York ",State="NY",Country="USA" });

           

            persons.Add(new staff() { Id = "2", FirstName = "Melissa", LastName = "Parker", Contact = "+1 (425) 882-8080"

                Mail = "melparker@gmail.com", Gender="F",Department="IT",Address= "1 Microsoft Way",PostalCode= "98052-8300",City= "Redmond ",State="WA",Country="USA" });

            

            persons.Add(new staff() { Id = "3", FirstName = "Tommy", LastName = "Paton", Contact = "+1 (867) 920-2233"

                Mail = "tommypat@hotmail.com", Gender="M",Department="Sales",Address= "5112 48 Street",PostalCode= "X1A 1N6",City= "Yellowknife ",State="NT",Country="Canada" });

           

            persons.Add(new staff() { Id = "4", FirstName = "Alice", LastName = "May", Contact = "+1 (408) 996-1010"

                Mail = "basahin@hotmail.com", Gender="F",Department="IT",Address= "1 Infinite Loop",PostalCode= "95014",City= "Cupertino ",State="CA",Country="USA" });

           

            persons.Add(new staff() { Id = "5", FirstName = "Michael", LastName = "Alon", Contact = "+1 (650) 644-3358"

                Mail = "michaelal57@gmail.com", Gender="M",Department="Sales",Address= "541 Del Medio Avenue",PostalCode= "94040-111",City= "Mountain View ",State="CA",Country="USA" });

           

            persons.Add(new staff() { Id = "6", FirstName = "Mike", LastName = "Carson", Contact = "+1 (775) 223-7665"

                Mail = "mikecarson33@hotmail.com", Gender="M",Department="Sales",Address= "801 W 4th Street",PostalCode= "89503",City= "Reno ",State="NV",Country="USA" });

            

             dataGridView1.DataSource = persons;

        }

    }

}

 

Bir makalenin daha sonuna geldik. Bir sonraki makalede görüşmek üzere. Bahadır ŞAHİN