" 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
  • 3286
  • 1

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

1 YORUM

  • Ryan

    Boom!So there you were, staring at your computer screen, a graveyard of failed online ventures haunting your hard drive.Youve tried everything, havent you?Courses that promised the moon but delivered moon dust.Foolproof tems that left you feeling like the fool.And lets not even talk about those late nights spent trying to decipher tech jargon that might as well have been ancient Sanskrit.But heres the kicker while you were busy pulling your hair out, the world didnt stop spinning.AI swooped in like a digital superhero, ready to save the day.And guess what?Its not here to replace you its here to empower you.Imagine having a tireless assistant, working 247 to drive traffic to your business: https:www.growwealthy.infoaifranchise .No more begging for clicks or burning cash on ads that perform worse than a dad joke at a teenagers party.This AI doesnt sleep, doesnt complain, and definitely doesnt ask for a raise.Its like having a team of Silicon Valley whiz kids in your pocket, minus the attitude and the obscene salaries.But heres the real magic you dont need to be a tech genius to use it.If you can click a button, youre overqualified.This is your chance to turn that hard drive of broken dreams into a treasure trove of success stories.Michael Cheney has just released AI Franchise get ready to let AI do the heavy lifting while you reap the rewards.Stop dreaming and start doing: https:www.growwealthy.infoaifranchise Best,Ryan PylesP.S. Dont let another one slip through your fingers: https:www.growwealthy.infoaifranchise . UNSUBSCRIBE: https:www.growwealthy.infounsubscribe?d=okanduzgun.com Address: 4821 Poe LanePaola, KS 66071

    14.02.2025

Yorum yazın

HAKKIMDA

KONULARI TAKİP EDİN

SOSYAL AĞLAR

  • Mesajınızı Gonderin