且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在鼠标点击时从datagridview加载图像到vb.net中的picturebox

更新时间:2023-09-21 20:07:16

你好!



像魅力一样工作!



Hello !

Working like charm !

Private Sub DataGridView1_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
        Dim pCell As New DataGridViewImageCell

        pCell = Me.DataGridView1.Item("ThumbNailPhotoDataGridViewImageColumn", e.RowIndex)
        Me.PictureBox1.Image = byteArrayToImage(pCell.Value)
    End Sub
    Private Function byteArrayToImage(ByVal byt As Byte()) As Image

        Dim ms As New System.IO.MemoryStream()
        Dim drwimg As Image = Nothing

        Try
            ms.Write(byt, 0, byt.Length)
            drwimg = New Bitmap(ms)
        Finally
            ms.Close()
        End Try

        Return drwimg

    End Function