i m working on a small application
its main function is to create a album and then add photos in the album.
i m using tree view for creating album and photos
i m using tree root as album and nodes as photos.
i have to also show photos when i click on photo name
i m using function showphoto for this purpose
i m using sql server to store picture in database and then retrieve from it
but i also want to generate thumbnail when i click on album name and all the images should be displayed as thumbnail on picbox
is there any control for this purpose or how i can do that?
i m also sending this application plz help me

Private Sub ShowPhoto(ByVal item As TreeItem)
        Try
            ' Create a command to select the selected photo
            Dim strCmd As String = [String].Format("SELECT photo FROM Photos WHERE id = {0}", item.Id)
            Dim cmd As New SqlCommand(strCmd, sqlConn)

            ' Set the description
            lblDesc.Text = item.Desc

            ' Get bytes return from stored proc
              Dim b As Byte() = CByte(cmd.ExecuteScalar())
            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
                DrawToScale(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

if i use above function to show photo
error comes on this line
Dim b As Byte() = CByte(cmd.ExecuteScalar())
and erroe says"Error	1	Value of type 'Byte' cannot be converted to '1-dimensional array of Byte'"
if i remove Cbyte from above line then application runs well but when i click on photo name then picture doesn't appear in picturebox.
and i m using showphoto function in below code snipts

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
                ' Set the description
                PictureBox.Image = Nothing
                ' Clear the image
                Return
            End If

            ' ...otherwise it is a photo
            ShowPhoto(item)
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub







using System;

namespace AlbumViewer
{
	public enum ItemType { Album, Photo };

	/// <summary>
	/// This is a helper class to contain information about
	/// treeview items
	/// </summary>
	public class TreeItem
	{
		private int m_nId = 0;
		private ItemType m_Type = ItemType.Photo;
		private string m_strDesc = "";

		public TreeItem(ItemType type, int nId, string strDesc)
		{
			m_Type = type;
			m_nId = nId;
			m_strDesc = strDesc;
		}

		public ItemType Type
		{
			get{ return m_Type; }
		}
		public int Id
		{
			get{ return m_nId; }
		}
		
		public string Desc
		{
			get{ return m_strDesc; }
			set{ m_strDesc = value; }
		}
	}
}



# Imports System
#
# Namespace AlbumViewer
#     Public Enum ItemType
#         Album
#         Photo
#     End Enum
#    
#     ''' <summary>
#     ''' This is a helper class to contain information about
#     ''' treeview items
#     ''' </summary>
#     Public Class TreeItem
#         Private m_nId As Integer = 0
#         Private m_Type As ItemType = ItemType.Photo
#         Private m_strDesc As String = ""
#        
#         Public Sub New(ByVal type As ItemType, ByVal nId As Integer, ByVal strDesc As String)
#             m_Type = type
#             m_nId = nId
#             m_strDesc = strDesc
#         End Sub
#        
#         Public ReadOnly Property Type() As ItemType
#             Get
#                 Return m_Type
#             End Get
#         End Property
#         Public ReadOnly Property Id() As Integer
#             Get
#                 Return m_nId
#             End Get
#         End Property
#        
#         Public Property Desc() As String
#             Get
#                 Return m_strDesc
#             End Get
#             Set
#                 m_strDesc = value
#             End Set
#         End Property
#     End Class
# End Namespace




# Imports System
#
# Namespace AlbumViewer
#     Public Enum ItemType
#         Album
#         Photo
#     End Enum
#    
#     ''' <summary>
#     ''' This is a helper class to contain information about
#     ''' treeview items
#     ''' </summary>
#     Public Class TreeItem
#         Private m_nId As Integer = 0
#         Private m_Type As ItemType = ItemType.Photo
#         Private m_strDesc As String = ""
#        
#         Public Sub New(ByVal type As ItemType, ByVal nId As Integer, ByVal strDesc As String)
#             m_Type = type
#             m_nId = nId
#             m_strDesc = strDesc
#         End Sub
#        
#         Public ReadOnly Property Type() As ItemType
#             Get
#                 Return m_Type
#             End Get
#         End Property
#         Public ReadOnly Property Id() As Integer
#             Get
#                 Return m_nId
#             End Get
#         End Property
#        
#         Public Property Desc() As String
#             Get
#                 Return m_strDesc
#             End Get
#             Set
#                 m_strDesc = value
#             End Set
#         End Property
#     End Class
# End Namespace
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.