C# DataGridView’ e Resim Ekleme

R

Rooster

only business
Super Moderator
Joined
Aug 10, 2019
Messages
3,215
Reaction score
4,728
Location
Milano
Bu yazımızda C# Datagridview kontrolüne dinamik olarak sütunlar ekleyip bu sütunlara ait özelliklerin nasıl ayarlanabileceğini ve Datagridview kontrolünde istenilen bir sütuna resim ekleme işleminiyapan bir örnek oluşturacağız.

Örneğimizi oluşturmaya başlayalım. Öncelikle Yeni bir Windows Form Application projesi açarak içine bir adet DatagridView kontrolü ekliyoruz. Datagridview alanlarını ve bu alanlara kayıt ekleme işlemlerini Form_Load olayında aşağıdaki şekilde gerçekleştiriyoruz.

Code:
private void Form1_Load(object sender, EventArgs e)
        {
            //Sütunları oluşturuyoruz.
            DataGridViewTextBoxColumn ad = new DataGridViewTextBoxColumn();
            DataGridViewTextBoxColumn soyad = new DataGridViewTextBoxColumn();
            DataGridViewImageColumn resim = new DataGridViewImageColumn();
 
            //Datagride alanlarımızı ekliyoruz.
            dataGridView1.Columns.Add(ad);
            dataGridView1.Columns.Add(soyad);
            dataGridView1.Columns.Add(resim);
 
            //Sütun başlıklarını ayarlıyoruz.
            ad.HeaderText = "ADI";
            soyad.HeaderText = "SOYADI";
            resim.HeaderText = "RESİM";
 
            //Sütun genişliklerini ayarlıyoruz.
            ad.Width = 120;
            soyad.Width = 150;
            resim.Width = 150;
 
            //Kayıt girişini gerçekleştiriyoruz.
            dataGridView1.Rows[0].Cells[0].Value = "Ahmet";
            dataGridView1.Rows[0].Cells[1].Value = "Cansever";
            dataGridView1.Rows[0].Cells[2].Value = Image.FromFile("Images/ahmetcansever.jpg"); 
        }
 
SPAM IS FORBIDDEN!
  • SPAMMERS ARE BANNED FROM THE FORUM AND CANNOT USE ANY OF THE CHEATS
  • For example: thanks, thx, very good, asdqwe, working, ty and so on!
  • For example: Writing the same message over and over. thanks, thx and so on!
  • Copying and copying someone else's message is prohibited.
  • It is forbidden to send messages to increase the number of comments on threads that you have no knowledge of.
  • Write your own opinion when commenting!
  • If you see spam message, please let us know with the REPORT button!

Tema düzenleyici

Top Bottom