INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Treeview and ImageList

Treeview and ImageList

(OP)
So I decided it was time to add some images to my treeview nodes, and why did I so stupidly think that was going to be something easy?

I've read about everything posted here, including the links to Doug Hennig's "Mother of all treeviews", but I am still not getting it for some reason. Doug's thing in my case I think it "too much". I just want something to show some images on my control, so please don't direct me back to his papers, I've read them, and played with his controls and still can't get it to work in my own forms (and for my liking it drags along too many other stuff that I won't ever use, and yes I could remove those parts, but then it starts to get very twitchy.

So fundamentally here is what I don't get. Following one of Mike Lewis's suggestions (from a post in like 2012), I made a container (TreeViewContainer), and I put two ActiveX controls into that Microsoft Treeview Control 6.0 and Microsoft ImageList Control 6.0 (I figured those sounded safely compatible).

One thing that perplexes me is, how does MS ImageList control EVER get populated? All the examples I see, (like in Sample) makes one reference to the world "world" which is clearly the icon it uses, but I can find nowhere in the code (not the form, not the objects, not the non-visual classes) that reference loading that image to the listview. It just starts getting "Used" but if I do that, and reference my images, of course, nothing is there.

The second odd part is how exactly does the image in the node get referenced? I see references to Objects in Doug's example that just don't make sense to me, because again I can find nowhere were those objects get created.

[rant] I have the tree working fine for loading the nodes otherwise. By Text, and giving them keys, everything is just as I want it, I just want to put the <expletive> icon in front of the nodes! [/endrant]


Best Regards,
Scott
MIET, MASHRAE, CDCP, CDCS, CDCE, CTDC, CTIA, ATS

"Everything should be made as simple as possible, and no simpler."hammer

RE: Treeview and ImageList

AS far as I remember, the image list is populated manually, using the context menu for it at designtime. And the rest should be easy, once you have the pictures in there.

Googling how to programmatically add an image to the ImageList I get ListImages.add(1,'key',LOADPICTURE("E:\develop\icons\foxdos.ico")). The first parameter is the index of the image (so this should not be an index you already had or you update that index image), the second parmeter is a key/name by which the image can be referenced and the third is obviously the image you load. You really need to go through the LOADPICUTRE function, only specifyfing the file name is not enough here, LOADPICTURE OLEfies the image file for the imagelist.

Adn then you have your key name, like you saw "world" in the example.

Last not least the Treeview Control has some property you need to set to the ImageList control so the treeview knows what Imagelist to use, just putting these two controls on one container isn't making the tree know his imagelist. The treevirew control has the ImageList property for that, which needs to be set to the Imagelistcontrol, eg This.Treeview.ImageList = This.ImageList, if This references the container they both are members of. So there is no drag&drop the imagelist into the treeview or such thing, it's really setting the property to the object reference.

That said, this old legacy treeview is lacking lots of features you may get from dbi or exontrol ActiveX controls, which both come with VFP samples. I used the exontrol eXGrid, a combination of grid and treeview. You can use it both as simple grid only or treeview only and combine the modes, too.

Bye, Olaf.

RE: Treeview and ImageList

(OP)
Ah, thanks Olaf, feeling totally stupid now. Forgot that right click on an ActiveX control gives you THAT control's properties! But I see your example as well to programmatically load, but that is a little odd if the list persists even after you destroy the object. No wonder it seem so "simple". I'll have to give this a try now, as I'm loading the image list now...

eXGrid sounds really interesting. I've never heard of it. I'll give it a lookup up too, because that would solve another problem I have. But in the interesting "knowing" I'll go ahead with what I've started first, and then I'll look at this after.
Thanks!

Best Regards,
Scott
MIET, MASHRAE, CDCP, CDCS, CDCE, CTDC, CTIA, ATS

"Everything should be made as simple as possible, and no simpler."hammer

RE: Treeview and ImageList

Here's how I programmatically load images into the Treeview:

this.oleImages.ListImages.Add(lnIconIndex,,LOADPICTURE(lcIconFile))

where:

- oleImages is the name of the ImageList control

- lnIconIndex is the index I want to assign to the image

- lcIconFile contains the image's filename (including path - remember, ActiveX controls don't know about VFP's default directory or search path).

I can look up some more code for you, Scott, if you need it.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: Treeview and ImageList

Quote (Scott)

that is a little odd if the list persists even after you destroy the object.
I don't know what you mean by that.

If you set any property of any control in the designer you also are not astonished it is saved and reloaded or are you astonished, that controls stay in the place you put them, for example?

Bye, Olaf.

RE: Treeview and ImageList

(OP)
Well, this seems more like dynamic data than a property. You're loading an image into a control.
And I have found, if you do this programmatically as you noted, they actually don't persist. It's cleared, and you have to reload them every time.

Best Regards,
Scott
MIET, MASHRAE, CDCP, CDCS, CDCE, CTDC, CTIA, ATS

"Everything should be made as simple as possible, and no simpler."hammer

RE: Treeview and ImageList

If you do it manually you don't store the picture, just the file names. You know you can open a form as a table and look inside what's stored. Here you want to go into details, which don't matter at all. Even I, who am interested in what are the most boring details for others, I don't care how the OLE class manages that.

If you put a normal image control on a VFP form, it also just remembers the file name and loads that.

And programmatically adding images, just adds them as runtime ole objects, which are gone. If you only put an image control on a form without setting picture, it also just shows the cross and no image, though when you set Picture at runtime that's shown and then gone, when you end the form. I don't see anything unusual here.

Bye, Olaf.

RE: Treeview and ImageList

(OP)
Yeah, I see your point. It just didn't occur to me.

Best Regards,
Scott
MIET, MASHRAE, CDCP, CDCS, CDCE, CTDC, CTIA, ATS

"Everything should be made as simple as possible, and no simpler."hammer

RE: Treeview and ImageList

(OP)
Hey Mike,
Thanks I downloaded your example, and looking at it now. Some of the "mystery" is revealed. So would this make for a good control on a form for picture thumbnails for an image gallery?

Best Regards,
Scott
MIET, MASHRAE, CDCP, CDCS, CDCE, CTDC, CTIA, ATS

"Everything should be made as simple as possible, and no simpler."hammer

RE: Treeview and ImageList

Quote:

So would this make for a good control on a form for picture thumbnails for an image gallery?

Yes, it would be perfect for that. And lots of other things too. I have used it as an alternative to a read-only grid or a listbox, for example.

Did you try the code I posted in my earlier post in this thread?

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: Treeview and ImageList

(OP)
Hi Mike,
You know I completely missed that code line. But I did get it working using something similar. So it's finally there, but I don't think I'm doing it the most eloquent of ways (as far as node loading goes). But for now I have the functionality I was looking for.
I was thinking a couple of weeks back about having a gallery, because we have tons of images for most of our sites too (photos), and this control could be extremely useful there. Rather than putting all the images into a table, with a lot of metadata, I can just point a directory at the control, and allow them to be "seen". This is great because we may have 600+ images for one site, but only care about 50 - 60 of them. This will make it easy to pluck the ones out we care about, and then only annotate those at a detailed record level.
So I can already see a use for this that I hadn't been thinking about until now.

Best Regards,
Scott
MIET, MASHRAE, CDCP, CDCS, CDCE, CTDC, CTIA, ATS

"Everything should be made as simple as possible, and no simpler."hammer

RE: Treeview and ImageList

Scott,

I hope I haven't misled you about showing thumbnails.

You can asign an image to any of the items in the list, and you can choose to show the items in either large icon or small icon view. What you can't do is to show the equavalent of Filmstrip or Thumbnails view in Windows Explorer.

I don't know whether this will be adequate for what you have in mind. You might need to put together a quick prototype in order to judge that.

Don't be put off by the word "icon". The images don't have to be ICO files. JPGs and BMPs are also supported.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: Treeview and ImageList

One easy way to list images in a VFP form is to use a webbrowser control and navigate it to a folder. That will show the folder content in the style of, Well, the IE browser, which comes close to the folder view of Windows Explorer Mike mentions. You just have not much control about what else the user sees and as you say you want them to be able to enter annotations, that'll surely be better done with either grid or treeview. I just wonder why the treeview, as this is rather a list only thing, I'd expect no sub nodes or sub trees, which would make the treview useful.

Bye, Olaf.

RE: Treeview and ImageList

(OP)
Hi Mike,
Thanks for the clarity. I am aware of the different image types supported (because I found out the hard way that ImageList doesn't support PNG, though all the VFP native objects where a image/picture is allowed, PNG is supported). It brought an interesting clarity to the difference between an ActiveX control and a native VFP control. But that said, the images are photos off a camera. The large icon view may still be ok. What I had in mind was to have your list view control in a pretty good amount of space, say maybe 1/2 the screen on the right. And that would just let you brows through all the thumbnails. Double clicking an image when then bring that into an Image control on the form, where you could then decide to annotate it or not. If you skip it, it does nothing. If you annotate it, then it saves a record in the table and the path reference in the memo field to that image. It would also give the option to rename the image at that time so it's more meaningful (instead of DSC0009253 it might be GeneratorEnclosureNorthTower.jpg). All this is to lead further down that path of the report I mentioned previously.
I'm horribly sick at the moment and that is frustrating because I'm just not making the progress that I want to make. And I alway already suffer this issue of my head coming up with more and better ideas than the speed in which I can implement them. (The curse of actually getting better at this! Thanks to you guys). So sorry if I'm a little slow to get back to some of these ideas at the moment. On the plus side it is a huge joy to be thinking like this again, and then seeing the outcome. Getting back up to speed in VFP was a frustrating learning curve, but I think I'm mostly through the curve now. If the appearance and function of the app is any indication, then I'm well and truly back.
Olaf, that's an interesting idea about a browser control. If I don't like what I get from Mike's control, I may give that a whirl.

Best Regards,
Scott
MIET, MASHRAE, CDCP, CDCS, CDCE, CTDC, CTIA, ATS

"Everything should be made as simple as possible, and no simpler."hammer

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close