" Umut, hiç görmeyen birine gökkuşağını anlatmak kadar zor ve imkansız... "

Categories

-

C# DataGridView Dikey Satirlama,Hizalama !!!

Bu makalede, bir DataGrid kontrolunu Dikey Satirlayip gösterecegiz... Burada normal modda (Yatay Satir) ve (Dikey Satir) bir DataTable nesnesi ile bazi bilgileri içeren bir DataGridView ile bir C # uygulamasi tasarlayacagiz...

Yeni bir C.NET 2010 Windows uygulamasi olusturun.

OleDbConnection baglanti = new OleDbConnectio(@"Provider=Microsoft.Ace.OLEDB.12.0;Data Source=" + Directory.GetCurrentDirectory() + @"\iller.mdb");

OleDbDataAdapter adap = null;

OleDbDataReader dr = null;

DataSet ds = null;

DataTable dt = null;


Bazi veriler ile dolu bir DataTable nesnesi olusturuyoruz :


public DataTable GetCustomers()

{

DataTable table = new DataTable();

OleDbDataAdapter adap = new OleDbDataAdapter("Select * From sehir", baglanti);

adap.Fill(table);

//table.TableName = "sehir";

//table.Columns.Add("Name", typeof(string));

//table.Columns.Add("Price", typeof(string));

//table.Columns.Add("Country", typeof(string));

//table.Rows.Add(new object[] { "Mohamad", "1700", "Egypt" });

//table.Rows.Add(new object[] { "Tarek", "550", "Syria" });

//table.Rows.Add(new object[] { "Gamal", "762", "Saudi Arabia" });

//table.AcceptChanges();

return table;

}



OnLoad olayina asagidaki metotlari ekleyin :



private void dikey_hizalama()

{

ds = new DataSet();

dt = new DataTable();

dt = GetCustomers();

ds.Tables.Add(dt);

DataSet new_ds = FlipDataSet(ds); // Flip the DataSet

DataView my_DataView = new_ds.Tables[0].DefaultView;

this.dataGridView1.DataSource = my_DataView;

}



private void yatay_hizalama()

{

baglanti.Open();

adap = new OleDbDataAdapter("Select * from sehir", baglanti);

dt = new DataTable();

adap.Fill(dt);

dataGridView2.DataSource = dt;

baglanti.Close();

}



private void Form1_Load(object sender, EventArgs e)

{

this.dataGridView1.ColumnHeadersVisible = false;

dikey_hizalama();

yatay_hizalama();

}


FlipDataSet yöntemi olusturuyoruz :


public DataSet FlipDataSet(DataSet my_DataSet)

{

DataSet ds = new DataSet();

foreach (DataTable dt in my_DataSet.Tables)

{

DataTable table = new DataTable();

for (int i = 0; i <= dt.Rows.Count; i++)

{

table.Columns.Add(Convert.ToString(i));

}

DataRow r;

for (int k = 0; k < dt.Columns.Count; k++)

{

r = table.NewRow();

r[0] = dt.Columns[k].ToString();

for (int j = 1; j <= dt.Rows.Count; j++)

r[j] = dt.Rows[j - 1][k];

table.Rows.Add(r);

}

ds.Tables.Add(table);

}

return ds;

}

Örnek çalismayi buradan indirebilirsiniz...

  • 0
  • 2696
  • 0

- BUNLARIDA GÖZDEN GEÇİREBİLİRSİNİZ -

HENÜZ YORUM YAPILMAMIŞ !

Yorum yazın

HAKKIMDA

KONULARI TAKİP EDİN

SOSYAL AĞLAR

  • Mesajınızı Gonderin