Adly 007
Adly 007

Reputation: 3

display Image in DataGridView not working

I want to show image (16*16px png file) in DataGridView. the header name of path pathname for each logo is "logo_dom", I compiled this and I have a text in each rows "System.Drawing.Bitmap" instead of logo picture.

        private void button1_Click(object sender, EventArgs e)
    {

        DataGridViewImageColumn imageColumn = new DataGridViewImageColumn();
        DataGridViewImageCell imageCell = new DataGridViewImageCell();
        Bitmap bmpImage = null;


        int number_of_rows = dgv_resultats.RowCount;
        for (int i = 0; i < number_of_rows-1; i++)
        {

            //bmpImage = (Bitmap)Image.FromFile(Application.StartupPath + dgv_resultats.Rows[1].Cells[1].Value.ToString(), true);

            bmpImage = (Bitmap)Image.FromFile(@"D:\LigueStats\Data\Logo\Ligue 1\EST.png", true);
            imageColumn.Image = bmpImage;

            imageColumn.ImageLayout = DataGridViewImageCellLayout.Stretch;

            dgv_resultats.Rows[i].Cells["logo_dom"].Value = bmpImage;



        }



    }

Upvotes: 0

Views: 2419

Answers (2)

Adly 007
Adly 007

Reputation: 3

the problem is in the type of the column in the datagridview, I ask you how I can change the type of loading the datagridview

the colmunType

Upvotes: 0

Nataniel Richardt
Nataniel Richardt

Reputation: 232

Try this:

DataGridViewImageColumn column = new DataGridViewImageColumn();
this.dataGridView1.Columns.Add(column);                      
string path = @"D:\LigueStats\Data\Logo\Ligue 1\EST.png";
Image img = Image.FromFile(path);
this.dataGridView1.Rows[0].Cells[0].Value = img;

EDIT:

string path = @"D:\LigueStats\Data\Logo\Ligue 1\EST.png";
Image img = Image.FromFile(path);
for (int i = 0; i < dgv_resultats.Rows.Count; i++)
{
    dgv_resultats.Rows[i].Cells["logo_dom"].Value = img;
}

Upvotes: 3

Related Questions