Tree View and Thumbnail problem

Apr 8 2008 1:48 AM
i m working on an application which main function is to store images into data base and then show them as thumbnail
i m using sql server2000 for this purpose
i m using a Tree View. I have set its name treeAlbum
i m using List View for the purpose of thumbnails.
my application creates a new album and then stores images into album
both album and photos are stored in to the data base
when I run my application agian, the images are shown again bcoz these are stored into database
i m using tree view so I use root of Tree View as album and nodes of tree views as photos
when i create a new album a new tree root is created and similarly when I save photos into the albums then nodes are created to that root
i think that u have undestood to this point so what is the problem, I didn't mention yet but I m going to tell u my actuall problem i m facing for few days and which is not being solved by me
Problem:
I want that when I click on album (tree view root) then all the photos stored in that album should be displayed as thumbnail and i m not succeeded in doing so
plz kindly help me how can i do that bcoz I have tried my self to do that but didn't succeeded.

code of my ShowThumbnail method is as follow


Private Sub ShowThumbnail(ByVal item As TreeItem)
        Dim cmd As New SqlCommand
        Dim sqlPhotoAlbum As SqlDataReader

        Try
            Dim SqlConn As New SqlConnection("workstation id=PC1;packet size=4096;integrated security=SSPI;initial catalog=master;persist security info=False")



            cmd.CommandText = [String].Format("SELECT photo FROM Photos WHERE id = {0}", item.Id)
            cmd.CommandType = CommandType.StoredProcedure
            cmd.Connection = SqlConn
            SqlConn.Open()
            sqlPhotoAlbum = cmd.ExecuteReader()
            ' Set the description
            lblDesc.Text = item.Desc

            ' Get bytes return from stored proc

           
            


            Dim imgList As New ImageList
            
            While (sqlPhotoAlbum.Read())
                Dim node As TreeNode = Nothing
                'Populate all images
                Dim data As Byte() = CType(sqlPhotoAlbum("Photo"), Byte())
                Dim ms As New System.IO.MemoryStream(data, 0, data.Length)
                Dim photo As Image = Image.FromStream(ms) ''

                imgList.Images.Add(sqlPhotoAlbum("PhotoName").ToString(), photo)
                imgList.ColorDepth = ColorDepth.Depth32Bit
                imgList.ImageSize = New Size(30, 30)


            End While
            treeAlbum.ImageList = imgList
            sqlPhotoAlbum.Close()
            SqlConn.Close()

        Catch e As Exception
            MessageBox.Show(e.Message)

        End Try


    End Sub

and i m calling above method in the following AfterSelect of tree view
 Private Sub treeAlbum_AfterSelect(ByVal sender As Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles treeAlbum.AfterSelect
        Try
            ' Disable edit controls if we were in edit mode
            If True = btnUpdate.Visible Then
                btnUpdate.Visible = False
                txtDesc.Visible = False
                lblDesc.Visible = True
            End If

            ' Retrieve the item info for this node
            Dim item As TreeItem = DirectCast(e.Node.Tag, TreeItem)

            ' If the selected item is an album...
            If ItemType.Album = item.Type Then
                lblDesc.Text = item.Desc

                ShowThumbnail(item)

                Return
            End If



        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub


thanks