日期:2014-05-17  浏览次数:21041 次

datagridview中图片绑定显示在picturebox上如何解决
现在我将图片以二进制流的形式存进数据库,然后通过条件显示在datagridview中,我想点击datagridview中的任意一行,则将相应的图片显示在picturebox上?  该如何解决?
点击datagridview的时候获取的是图片那一列的数据时二进制流还是image呢?  望各位大侠帮帮忙
图片 DataGridView 二进制

------解决方案--------------------

if (dataGridViewX1.Rows.Count == 0 
------解决方案--------------------
 dataGridViewX1.Columns.Count == 0 
------解决方案--------------------
 dataGridViewX1.CurrentCell.RowIndex == -1 
------解决方案--------------------
 dataGridViewX1.CurrentCell.ColumnIndex == -1)
                return;
            int index = dataGridViewX1.CurrentCell.RowIndex;
            byte[] imagedata = (byte[])(dataGridViewX1.Rows[index].Cells[3].Value);
            MemoryStream myStream = new MemoryStream();
            foreach(byte a in imagedata )
            {
                myStream.WriteByte(a);
            }
            Image myimage = Image.FromStream(myStream);
            myStream.Close();
            this.pictureBox1.Image = myimage;
            this.pictureBox1.Refresh();