-
May 4th, 2013, 01:28 PM
#1
Thread Starter
New Member
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
-
May 4th, 2013, 01:51 PM
#2
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
-
May 4th, 2013, 02:00 PM
#3
Thread Starter
New Member
Re: how to fill treeview images using recordset dynamically
Thank You sir..
-
May 5th, 2013, 04:40 PM
#4
Thread Starter
New Member
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
-
May 5th, 2013, 05:04 PM
#5
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.
-
May 7th, 2013, 01:47 AM
#6
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
-
May 7th, 2013, 05:51 AM
#7
Banned
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
-
May 7th, 2013, 06:54 AM
#8
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.
-
May 7th, 2013, 02:55 PM
#9
Thread Starter
New Member
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 ?
-
May 7th, 2013, 03:08 PM
#10
Thread Starter
New Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|