Results 1 to 10 of 10

Thread: how to fill treeview images using recordset dynamically

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2013
    Posts
    10

    how to fill treeview images using recordset dynamically

    hello everyone... this is my first ever post here..

    i'm having a treeview control and i want to add categories, products and images dynamically using recordset .. i m able to do for categories and products
    but unable to work with images that i have stored in access database

    Private Sub CreateCategoryNodes()

    Set rs = New ADODB.Recordset

    Dim strSQL As String
    Dim nodX As Node

    TreeView1.LineStyle = tvwRootLines
    strSQL = "Select * from groups"
    rs.Open strSQL, mycon, adOpenStatic, adLockOptimistic
    ' loop through the rows in the recordset
    rs.MoveFirst
    Do Until rs.EOF
    Me.TreeView1.Nodes.Add Text:=rs!groupname, _
    Key:="Cat=" & CStr(rs!groupID)
    rs.MoveNext
    Loop
    rs.Close
    Set rs = Nothing
    End Sub

    Private Sub CreateProductNodes()
    Set rs = New ADODB.Recordset

    Dim strSQL As String
    Dim nodX As Node

    TreeView1.LineStyle = tvwRootLines

    Dim img As ListImage

    Dim i As Integer

    strSQL = "Select * from products"
    rs.Open strSQL, mycon, adOpenStatic, adLockOptimistic

    ' loop through the rows in the recordset
    rs.MoveFirst
    Do Until rs.EOF

    For i = 0 To ImageList1.ListImages.Count
    With ImageList1.ListImages
    .Add , "Image1", rs!Image
    End With
    Next


    TreeView1.Nodes.Add Relationship:=tvwChild, Relative:="Cat=" & CStr(rs!groupID), _
    Text:=rs!ProductName, Key:="Prod=" & CStr(rs!productID), Image:=rs!Image
    rs.MoveNext
    Loop
    rs.Close
    Set rs = Nothing
    End Sub

  2. #2
    PowerPoster Spoo's Avatar
    Join Date
    Nov 2008
    Location
    Right Coast
    Posts
    2,656

    Re: how to fill treeview images using recordset dynamically

    Don

    I haven't worked with TreeView so I can't really help.

    But, FWIW, I've heard that it is a bad idea to store images in Access.
    The "better" way is to store the images as BMPs or JPEGs in a directory with specific names/
    Then, in Access, all you'd do is store the file names.

    I realize this would mean rather substantial changes for you, but possibly you could at least
    test it on one or 2 images. If you can get that working, then you'll be able to evaluate if the
    overall effort is worth it.

    Spoo

  3. #3

    Thread Starter
    New Member
    Join Date
    May 2013
    Posts
    10

    Re: how to fill treeview images using recordset dynamically

    Thank You sir..

  4. #4

    Thread Starter
    New Member
    Join Date
    May 2013
    Posts
    10

    Re: how to fill treeview images using recordset dynamically

    But still after that.. i cant load images to my TreeView control.., i have added an imagelist control to my form, that would take up all the images for treeview .. but the imagelist control takes only index number( that would be static), now from where to get that index number when i'm pulling data from recordset ??.. i have stored the image name and path in the database. please help :/ i'm unable to fix this

  5. #5
    PowerPoster Spoo's Avatar
    Join Date
    Nov 2008
    Location
    Right Coast
    Posts
    2,656

    Re: how to fill treeview images using recordset dynamically

    Sorry ,, I am unable to.

    As I mentioned, I haven't worked with TreeView so I can't really help.
    Hopefully someone else can.

  6. #6
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: how to fill treeview images using recordset dynamically

    This looks suspicious:
    Code:
    For i = 0 To ImageList1.ListImages.Count
        With ImageList1.ListImages
            .Add , "Image1", rs!Image
        End With
    Next
    If ImageList1 has no images then the loop will not execute. I would have thought you'd want to add images each with a different key and then use that to populate the TreeView.


    Try something like this
    Code:
    strSQL = "Select * from products"
    rs.Open strSQL, mycon, adOpenStatic, adLockOptimistic
    
    ' loop through the rows in the recordset
    Do Until rs.EOF
        With ImageList1.ListImages
        '
        ' Append the ProductID to the text "Image" to give a unique key for the Image
        '
            .Add , "Image" & CStr(rs!productID), rs!Image
        End With
        TreeView1.Nodes.Add Relationship:=tvwChild, Relative:="Cat=" & CStr(rs!groupID), _
        Text:=rs!ProductName, Key:="Prod=" & CStr(rs!productID), Image:="Image" & CStr(rs!productID)
    rs.MoveNext
    Loop
    Last edited by Doogle; May 7th, 2013 at 01:54 AM. Reason: Used ProductID rather than i for the key

  7. #7
    Banned
    Join Date
    Nov 2012
    Posts
    1,171

    Re: how to fill treeview images using recordset dynamically

    why dont you use images from /folder easy better , if u store images in application your appication will take up large space

  8. #8
    Fanatic Member
    Join Date
    Jan 2013
    Posts
    759

    Re: how to fill treeview images using recordset dynamically

    > ... the imagelist control takes only index number
    Not true.
    You can use the Key property on each image to give them meaningful names and index the ListImages collection using that name.

    Regards, Phill W.

  9. #9

    Thread Starter
    New Member
    Join Date
    May 2013
    Posts
    10

    Re: how to fill treeview images using recordset dynamically

    Thank you all for your replies.... i'm glad
    well i'm again paused here ------ error says "invalid picture"
    With ImageList1.ListImages

    .Add , "Image" & CStr(rs!productID), rs!Image ' the image format is OLE type in access database and the images are (.bmp) , is it the wrong type i hv given there ?

  10. #10

    Thread Starter
    New Member
    Join Date
    May 2013
    Posts
    10

    Re: how to fill treeview images using recordset dynamically

    though i got it by another method .. i.e holding the image path in database and then retrieving here by loadpicture method... :/

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width