Welcome to Dream.In.Code
Become a VB.NET Expert!

Join 150,096 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 1,828 people online right now. Registration is fast and FREE... Join Now!




double clicking the thumbnail

 
Reply to this topicStart new topic

double clicking the thumbnail

aamir_mustafa2007@msn.com
18 Apr, 2008 - 08:44 PM
Post #1

New D.I.C Head
*

Joined: 3 Jul, 2007
Posts: 18


My Contributions
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

CODE
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"
CODE
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
CODE
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.


Attached File(s)
Attached File  Thumbnail.zip ( 75.74k ) Number of downloads: 80
User is offlineProfile CardPM
+Quote Post

PsychoCoder
RE: Double Clicking The Thumbnail
18 Apr, 2008 - 09:29 PM
Post #2

using DIC.Core;
Group Icon

Joined: 26 Jul, 2007
Posts: 9,483



Thanked: 161 times
Dream Kudos: 9075
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions
Moved to VB.NET smile.gif
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 12:14AM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month