2013-06-28 2 views
4

J'ai un champ DataGridViewImageColumn, et pour chaque ligne du champ, en fonction d'une condition, j'ajoute une image différente. Quelqu'un sait comment je peux le faire dans Windows Forms?Comment ajouter une image dans mon DataGridViewImageColumn?

if (dgvAndon.Rows[e.RowIndex].Cells["urgencyOrder"].ToString() == "1") 
{ 
    //Here I want to add the image in the image property field DataGridViewImageColumn. 
} 

Répondre

5
  1. Ajoutez votre image dans Resources.resx sous dossier propriétés. (Ex Picture1.jpeg.)
  2. Ajouter un DataGridViewImageColumn dans votre DataGridView
  3. Ajouter une image de cette façon:

    for (int row = 0; row <= [YourDataGridViewName].Rows.Count - 1; row++) 
    { 
        ((DataGridViewImageCell)gvFiles.Rows[row].Cells[1]).Value = Properties.Resources.Picture1 
    } 
    
+0

Oo, merci! Travaillé .. – user1792343

0

utiliser ce code

protected void gridView1_RowDataBound(Object sender, GridViewRowEventArgs args) 
    { 
    if(args.Row.RowType == DataControlRowType.DataRow) 
    { 
     Image img = (Image) e.Row.FindControl("Image1"); 
     img.ImageUrl = setImageURLHere; 
    } 
    } 
+1

Ceci est pour un formulaire Web. L'affiche demandait un winform. –

0

utilisent ce code:

 DataGridViewImageColumn iconColumn = new DataGridViewImageColumn(); 
     iconColumn.Name = "AirplaneImage"; 
     iconColumn.HeaderText = "Airplane Image"; 
     dataGridView1.Columns.Insert(5, iconColumn); 

     for (int row = 0; row < dataGridView1.Rows.Count - 1; row++) 
     { 
      Bitmap bmp = new Bitmap(Application.StartupPath + "\\Data\\AirPlaneData\\" + dt.Rows[row][4]); 
      ((DataGridViewImageCell)dataGridView1.Rows[row].Cells[5]).Value = bmp; 
     } 
Questions connexes