将图像从Gridview提取到insertform

时间:2017-12-30 11:50:23

标签: c#

我收到错误

  

无法转换'字符串'到byte []

我发现了问题..图像是问题,在双击gridview上的任何特定记录后,它不会以entry_jewelry形式显示。

我有两种形式:

  1. 查看珠宝列表:"它显示了gridview中所有珠宝的记录"。
  2. 珠宝的进入:"在这里我们输入股票"。
  3. 我尝试了很多将图像从gridview转回到"珠宝的入口"

    它不起作用请帮助我。

    我的gridview代码:

    private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
    {
            S_Jewelry myForm = new S_Jewelry();
    
            myForm.Stock_Type.Text = this.dataGridView1.CurrentRow.Cells[1].Value.ToString();
            myForm.txt_stock_no.Text = this.dataGridView1.CurrentRow.Cells[2].Value.ToString();
            myForm.txt_qty.Text = this.dataGridView1.CurrentRow.Cells[3].Value.ToString();
            myForm.combo_itemk_description.Text = this.dataGridView1.CurrentRow.Cells[4].Value.ToString();
            myForm.combo_item_type.Text = this.dataGridView1.CurrentRow.Cells[5].Value.ToString();
            myForm.txt_no_of_gems.Text = this.dataGridView1.CurrentRow.Cells[6].Value.ToString();
            myForm.txt_gem_type.Text = this.dataGridView1.CurrentRow.Cells[7].Value.ToString();
    
            byte[] pic = (Byte[])dataGridView1.CurrentRow.Cells[8].Value.ToString();
            MemoryStream stream = new MemoryStream(pic);
            myForm.pb1.Image =Image.FromStream(stream);
            //  myForm.pb1.Text = this.dataGridView1.CurrentRow.Cells[8].Value.ToString();
    
            myForm.txt_gem_weight.Text = this.dataGridView1.CurrentRow.Cells[9].Value.ToString();
            myForm.txt_no_of_other_gems.Text = this.dataGridView1.CurrentRow.Cells[10].Value.ToString();
            myForm.txt_other_gems.Text = this.dataGridView1.CurrentRow.Cells[11].Value.ToString();
            myForm.txt_weight_of_other_gems.Text = this.dataGridView1.CurrentRow.Cells[12].Value.ToString();
            myForm.txt_cost.Text = this.dataGridView1.CurrentRow.Cells[13].Value.ToString();
            myForm.ShowDialog();
    }
    

1 个答案:

答案 0 :(得分:0)

尝试使用图像源加载图片

//save image location in gridview (C:\\folder\\image.jpg)
string pic = dataGridView1.CurrentRow.Cells[8].Value.ToString();
myForm.pb1.Image =Image.FromFile(pic);