How to add an image to my DataGridViewImageColumn?

I have a DataGridViewImageColumn field, and for each row of the field, depending on the condition, I add another image. Does anyone know how I can do this in Windows Forms?

 if (dgvAndon.Rows[e.RowIndex].Cells["urgencyOrder"].ToString() == "1") { //Here I want to add the image in the image property field DataGridViewImageColumn. } 
+7
source share
4 answers
  • Add your image to the Resources.resx folder under the properties folder. (e.g. Picture1.jpeg)
  • Add DataGridViewImageColumn to DataGridView
  • Add an image this way:

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

use this 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; } 
+2
source

use this 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; } } 
0
source
 string FileName = null; OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.RestoreDirectory = true; openFileDialog.Filter = "All picture files (*.BMP;*.JPG;*.GIF)|*.BMP;*.JPG;*.GIF"; if (openFileDialog.ShowDialog() == DialogResult.OK) { FileName = openFileDialog.FileName; //pictureBox2.Image = Image.FromFile(FileName); } 
0
source

Source: https://habr.com/ru/post/1488691/


All Articles