2017-03-19 59 views
1

我怎麼能顯示一個圖像,我已經存儲在數據庫中出現在圖片框,當我點擊它在datagridview ...我還是相當新的編碼c#所以我不會「噸真的知道如何做到這一點從datagridview點擊顯示圖像

私人無效dataGridView1_CellClick(對象發件人,DataGridViewCellEventArgs E) {

 if (dataGridView1.SelectedRows.Count > 0) 
     { 
      string ItemID = dataGridView1.SelectedRows[0].Cells[0].Value + string.Empty; 
      string ItemName = dataGridView1.SelectedRows[0].Cells[1].Value + string.Empty; 
      string SupplierID = dataGridView1.SelectedRows[0].Cells[2].Value + string.Empty; 
      string Quantity = dataGridView1.SelectedRows[0].Cells[3].Value + string.Empty; 
      string Price = dataGridView1.SelectedRows[0].Cells[4].Value + string.Empty; 

      MemoryStream ms = new MemoryStream(); 
      Bitmap img = (Bitmap)dataGridView1.CurrentRow.Cells[1].Value; 
      img.Save(ms, ImageFormat.Jpeg); 
      pictureBox1.Image = Image.FromStream(ms); 

      textBox1.Text = ItemID; 
      textBox2.Text = ItemName; 
      textBox3.Text = SupplierID; 
      textBox4.Text = Quantity; 
      textBox5.Text = Price; 
     } 
+0

爲什麼要訪問Cell [1],您已經將ItemName?另外:(正確的)單元格有哪些數據類型?它是一個Imagecolumn嗎?然後,您可以簡單地使用其FormattedValue並將其分配給pbx.Image。 – TaW

回答

0

如果我理解你的問題正確,你需要使用PictureBox.Refresh()。例如:設置圖像使用刷新方法後,例如:

pictureBox1.Image = Image.FromStream(ms); 
pictureBox1.Refresh(); 
+0

感謝您的建議,但它仍然是相同的@藝術 – Robotaku