如何在单元格单击时从gridview将图像检索到pictureBox? [英] How can i retrieve image to pictureBox from gridview on cell click ?

查看:69
本文介绍了如何在单元格单击时从gridview将图像检索到pictureBox?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用3层存储过程和VB.net.
现在,我单击gridview,然后想在文本框和pictureBox中显示数据以更新信息.
问题是,如何将照片检索到图片框?

这是我的代码

I''m using Stored Procedure,3 tier and VB.net.
Now, i click the gridview and then want to show the data in textboxes and pictureBox to update the informations.
The problem is that , how can i retrieve photo to picture box?

Here is my code

Private Sub gdCompany_CellClick(ByVal sender As System.Object, ByVal e As Telerik.WinControls.UI.GridViewCellEventArgs) Handles gdCompany.CellClick

      btnSave.Text = "ျပင္ရန္"
      txtCompanyName.Text = gdCompany.CurrentRow.Cells(1).Value.ToString()
      txtDescription.Text = gdCompany.CurrentRow.Cells(2).Value.ToString()
      txtPhoneNo.Text = gdCompany.CurrentRow.Cells(3).Value.ToString()
      txtFaxNo.Text = gdCompany.CurrentRow.Cells(4).Value.ToString()
      txtEmail.Text = gdCompany.CurrentRow.Cells(5).Value.ToString()
      txtWebsite.Text = gdCompany.CurrentRow.Cells(6).Value.ToString()
      ddlBankName.SelectedValue = Convert.ToInt32(gdCompany.CurrentRow.Cells(7).Value.ToString())
      ddlBankBranch.SelectedValue = Convert.ToInt32(gdCompany.CurrentRow.Cells(8).Value.ToString())
      txtBankAccountNo.Text = gdCompany.CurrentRow.Cells(9).Value.ToString()
      txtAddress.Text = gdCompany.CurrentRow.Cells(10).Value.ToString()

      'picCompanyLogo.Image = Convert.ToByte(gdCompany.CurrentRow.Cells(15).Value.ToString())
     
      txtCompanyName.Focus()
  End Sub

推荐答案

现在可以使用此解决方案了.

now it is ok with this solution.

Try
           'Get image data from gridview column.
           Dim imageData As Byte() = DirectCast(gdCompany.CurrentRow.Cells(15).Value, Byte())
           'Initialize image variable
           Dim newImage As Image
           'Read image data into a memory stream
           Using ms As New MemoryStream(imageData, 0, imageData.Length)
               ms.Write(imageData, 0, imageData.Length)
               'Set image variable value using memory stream.
               newImage = Image.FromStream(ms, True)
           End Using
           'set picture
           picCompanyLogo.Image = newImage
       Catch ex As Exception
           MessageBox.Show(ex.ToString())
       End Try


这篇关于如何在单元格单击时从gridview将图像检索到pictureBox?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆