User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the VB.NET section within the Software Development category of DaniWeb, a massive community of 392,044 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,252 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our VB.NET advertiser:
Views: 403 | Replies: 1
Reply
Join Date: Mar 2008
Posts: 7
Reputation: aamir55 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
aamir55 aamir55 is offline Offline
Newbie Poster

Tree view Problem...Plz help

  #1  
Mar 28th, 2008
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
  1. Private Sub ShowPhoto(ByVal item As TreeItem)
  2. Try
  3. ' Create a command to select the selected photo
  4. Dim strCmd As String = [String].Format("SELECT photo FROM Photos WHERE id = {0}", item.Id)
  5. Dim cmd As New SqlCommand(strCmd, sqlConn)
  6.  
  7. ' Set the description
  8. lblDesc.Text = item.Desc
  9.  
  10. ' Get bytes return from stored proc
  11. Dim b As Byte() = CByte(cmd.ExecuteScalar())
  12. If b.Length > 0 Then
  13. ' Open a stream for the image and write the bytes into it
  14. Dim stream As New System.IO.MemoryStream(b, True)
  15. stream.Write(b, 0, b.Length)
  16.  
  17. ' Draw photo to scale of picturebox
  18. DrawToScale(New Bitmap(stream))
  19.  
  20. ' Close the stream and delete the temp file
  21. stream.Close()
  22. End If
  23. Catch e As Exception
  24. MessageBox.Show(e.Message)
  25. End Try
  26. End Sub
  27.  
  28. if i use above function to show photo
  29. error comes on this line
  30. Dim b As Byte() = CByte(cmd.ExecuteScalar())
  31. and erroe says"Error 1 Value of type 'Byte' cannot be converted to '1-dimensional array of Byte'"
  32. 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.
  33. and i m using showphoto function in below code snipts
  34.  
  35. Private Sub treeAlbum_AfterSelect(ByVal sender As Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles treeAlbum.AfterSelect
  36. Try
  37. ' Disable edit controls if we were in edit mode
  38. If True = btnUpdate.Visible Then
  39. btnUpdate.Visible = False
  40. txtDesc.Visible = False
  41. lblDesc.Visible = True
  42. End If
  43.  
  44. ' Retrieve the item info for this node
  45. Dim item As TreeItem = DirectCast(e.Node.Tag, TreeItem)
  46.  
  47. ' If the selected item is an album...
  48. If ItemType.Album = item.Type Then
  49. lblDesc.Text = item.Desc
  50. ' Set the description
  51. PictureBox.Image = Nothing
  52. ' Clear the image
  53. Return
  54. End If
  55.  
  56. ' ...otherwise it is a photo
  57. ShowPhoto(item)
  58. Catch ex As Exception
  59. MessageBox.Show(ex.Message)
  60. End Try
  61. End Sub
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69. using System;
  70.  
  71. namespace AlbumViewer
  72. {
  73. public enum ItemType { Album, Photo };
  74.  
  75. /// <summary>
  76. /// This is a helper class to contain information about
  77. /// treeview items
  78. /// </summary>
  79. public class TreeItem
  80. {
  81. private int m_nId = 0;
  82. private ItemType m_Type = ItemType.Photo;
  83. private string m_strDesc = "";
  84.  
  85. public TreeItem(ItemType type, int nId, string strDesc)
  86. {
  87. m_Type = type;
  88. m_nId = nId;
  89. m_strDesc = strDesc;
  90. }
  91.  
  92. public ItemType Type
  93. {
  94. get{ return m_Type; }
  95. }
  96. public int Id
  97. {
  98. get{ return m_nId; }
  99. }
  100.  
  101. public string Desc
  102. {
  103. get{ return m_strDesc; }
  104. set{ m_strDesc = value; }
  105. }
  106. }
  107. }
  108.  
  109.  
  110.  
  111. # Imports System
  112. #
  113. # Namespace AlbumViewer
  114. # Public Enum ItemType
  115. # Album
  116. # Photo
  117. # End Enum
  118. #
  119. # ''' <summary>
  120. # ''' This is a helper class to contain information about
  121. # ''' treeview items
  122. # ''' </summary>
  123. # Public Class TreeItem
  124. # Private m_nId As Integer = 0
  125. # Private m_Type As ItemType = ItemType.Photo
  126. # Private m_strDesc As String = ""
  127. #
  128. # Public Sub New(ByVal type As ItemType, ByVal nId As Integer, ByVal strDesc As String)
  129. # m_Type = type
  130. # m_nId = nId
  131. # m_strDesc = strDesc
  132. # End Sub
  133. #
  134. # Public ReadOnly Property Type() As ItemType
  135. # Get
  136. # Return m_Type
  137. # End Get
  138. # End Property
  139. # Public ReadOnly Property Id() As Integer
  140. # Get
  141. # Return m_nId
  142. # End Get
  143. # End Property
  144. #
  145. # Public Property Desc() As String
  146. # Get
  147. # Return m_strDesc
  148. # End Get
  149. # Set
  150. # m_strDesc = value
  151. # End Set
  152. # End Property
  153. # End Class
  154. # End Namespace
  155.  
  156.  
  157.  
  158.  
  159. # Imports System
  160. #
  161. # Namespace AlbumViewer
  162. # Public Enum ItemType
  163. # Album
  164. # Photo
  165. # End Enum
  166. #
  167. # ''' <summary>
  168. # ''' This is a helper class to contain information about
  169. # ''' treeview items
  170. # ''' </summary>
  171. # Public Class TreeItem
  172. # Private m_nId As Integer = 0
  173. # Private m_Type As ItemType = ItemType.Photo
  174. # Private m_strDesc As String = ""
  175. #
  176. # Public Sub New(ByVal type As ItemType, ByVal nId As Integer, ByVal strDesc As String)
  177. # m_Type = type
  178. # m_nId = nId
  179. # m_strDesc = strDesc
  180. # End Sub
  181. #
  182. # Public ReadOnly Property Type() As ItemType
  183. # Get
  184. # Return m_Type
  185. # End Get
  186. # End Property
  187. # Public ReadOnly Property Id() As Integer
  188. # Get
  189. # Return m_nId
  190. # End Get
  191. # End Property
  192. #
  193. # Public Property Desc() As String
  194. # Get
  195. # Return m_strDesc
  196. # End Get
  197. # Set
  198. # m_strDesc = value
  199. # End Set
  200. # End Property
  201. # End Class
  202. # End Namespace
Last edited by WolfPack : Mar 28th, 2008 at 9:37 am. Reason: Added code tags. Use them when you post code.
Attached Files
File Type: zip E-Photographer.zip (81.6 KB, 0 views)
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Mar 2008
Posts: 1
Reputation: sunnyjaswani is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
sunnyjaswani sunnyjaswani is offline Offline
Newbie Poster
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb VB.NET Marketplace
Thread Tools Display Modes

Other Threads in the VB.NET Forum

All times are GMT -4. The time now is 11:14 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC