Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Add Image in TreeView

Status
Not open for further replies.

alisaif

ISP
Apr 6, 2013
418
AE
Hi,

I have generated a treeview and now I want the following:

1. Add images/icons
2. Select only those records which have been selected through checkbox.

How can I do so?

Thanks

Saif
 
Which treeview did you use?

The MS Treeview perhaps. It must be ActiveX anyway. You don't find documentation for any ActiveX in VFP, not even the controls mentioned in the redist.txt, because their methods and properties are documented in the MSDN library, which last came with VFP6, as that was part of Visual Studio 6.

You can find some info on the ms treeview on

To add images you need a seperate ActiveX Control ImageList. If you name your treeview yourtreeview and your imagelist yourimagelist, you make the pictures of the imagelist available to the treeview by setting thisform.yourtreeview.Imagelist = thisform.yourimagelist

To add images to the imagelist you have to use the context menu and choose the menu item "ImageListCtrl Proeprties", not the normal VFP Proeprties context menu item. Then you get to a dialog, with a tab "Images", where you can watch, insert or remove images.

I don't know for sure about the checkbox, nodes should have a checked property, so you could find all checked nodes with
Code:
For Each loNode In Thisform.yourtreeview.Nodes
   If loNode.checked
      ? loNode.Text
   Endif
Endfor

Bye, Olaf.
 
Thanks Olaf for the reply, your piece of code is working perfectly but I still need some guidance on images.

thisform.yourtreeview.Imagelist = thisform.yourimagelist

in my,

ThisForm.Tree1.ImageList = ThisForm.TreeImages

Where to put this code? In this init of the form.?

Thanks

Saif
 
Well, as it has to do with the treeview, it would perhaps be best in treeview init,
but as these are two independant controls and it would depend on taborder which is there first, the form init is fine. In form init you can be sure both treeview and imagelist exist.

Bye, Olaf.
 
For what it's worth, the way I handle this is to have a custom treeview class. It is based on a native Container class, and it contains the treeview and the image list. I have code at the Container level which handles the initialisation of the image list, as well as all the other housekeeping.

The advantage is that the treeview and the image list always stay together - I only have to drop the one object on a form. I do much the same thing with the list view.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
That's a good approach, Mike.
Keep things encapsulated, that won't work without each other.

First of all, we should clarify to Alisaif: There is no simultaneous init of all controls of a form, so ThisForm.Tree1.ImageList = ThisForm.TreeImages only works in Tree1.Init(), if the TreeImages control was inited before.

If you go for riscs, you can set taborder, actually I'm not sure, I think it's rather the zorder on the form.

...testing...

Yes, controls are inited in zorder, so what you "Send to Back" in the Format menu of the form or class editor, is inited before what is in front of it, because that order is determining the record order in the scx or vcx, I assume.

You see, "I assume", even though I tested, this is just a test, this observation of a test is no proof. Mike only relies on what's working in any case, the outer container is the last thing initing, that's valid for the form, or in case you define a container class, the container is inited after all controls in it (and before the form, on which you put it).

Anyway, if you define such compound controls depnding on each other being present, a container is a good base class for that to have a level where the objects exist, that depend on each other, and container.init() then is the event to put any initialisation acting on two or more inner controls. There is another base class called "control", that is meant for designing such compound controls, not only in case of combining activex controls.The control class has it's pros and cons and in the end the container is simpler to use, unless you want to be real nerdy.

Ideally you don't use the native container class, but your own container classs with borderwidth set to 0 and backstyle transparent, so such containers of compound controls integrate seamless onto forms.

If you put Tree1 and TreeImages into your container, the Container.Init() code needs to be:
Code:
This.Tree1.ImageList = This.TreeImages
Not Thisform, of course. Don't forget to adjust that.

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top