double clicking on thumbnail problem----plz help me

Apr 18 2008 7:49 AM
i want to show the photo on Form2 by double cliking on the thumbnail
i m using list view for generating thumbnail of each image
i m retrieving images from sql server data base
actually i want to invoke double click event of List View so that i can see the image on Form2
i have written below method to show photo on form2

Private FotoInstance As frmPic
Private Sub ShowImage(ByVal bmp As Image)
        FotoInstance.PictureBox1.Width = 150
        FotoInstance.PictureBox1.Height = 115
        FotoInstance.PictureBox1.Image = New Bitmap(bmp)
        FotoInstance.PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
    End Sub

in second method i try to load image from data base and here i call previous method"Show Image"
Private Sub Thumbnail(ByVal item As ListViewItem)
        Try
            ' Create a command to select the selected photo
            Dim strCmd As String = [String].Format("SELECT photo FROM Photos WHERE id = {0}", item.ListView)
            Dim cmd As New SqlCommand(strCmd, SqlConn)
            ' Get bytes return from stored proc
            Dim b As Byte() = CType(cmd.ExecuteScalar(), Byte())
            If b.Length > 0 Then
                ' Open a stream for the image and write the bytes into it
                Dim stream As New System.IO.MemoryStream(b, True)
                stream.Write(b, 0, b.Length)
                ' Draw photo to scale of picturebox
                ShowImage(New Bitmap(stream))
                ' Close the stream and delete the temp file
                stream.Close()
            End If
        Catch e As Exception
            MessageBox.Show(e.Message)
        End Try
    End Sub
and lastly here i invoke double click event of List View to show the image on form2
Private Sub thumbList_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles thumbList.DoubleClick
        Try
            Dim item As ListViewItem
            
            Thumbnail(item)
        Catch ex As Exception

        End Try

    End Sub

but when i double click on a thumbnail then this message is displayed"Object reference not set to an instance of an object"
plz kindly tell me how can I properly show the image on form by just clicking on thumbnail
kindly guide me
* Remember that i load images from database not from disk.

Answers (1)