Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Adding icons to TreeView
Message
De
23/03/2005 09:29:53
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Contrôles ActiveX en VFP
Versions des environnements
Visual FoxPro:
VFP 9
OS:
Windows XP SP2
Network:
Windows 2000 Server
Database:
Visual FoxPro
Divers
Thread ID:
00998066
Message ID:
00998396
Vues:
39
I'd need an example to see how can I add icons to treeview, thanks.

The first thing you need to do is to add an ImageList control to your form. You can store images in the control at design time using the ImageList properties or at run time by using the Add() method of its ListImages collection. If you are adding images visually, make sure that you set the size for the images on the ‘General’ tab of its property sheet before you start to add them because once you have added images to the control, you cannot change the image size. Once you have done this, you are ready to add the images. Clicking on the ‘Insert Picture’ button brings up a dialog that allows you to select an image.

To add images to the ImageList programmatically, you can use code like this:
This.ListImages.Add( [ nIndex ], [ cKey ], oPicture )
The nIndex argument is optional and specifies the image’s order in the ListImages collection. If no index is specified, the image is added to the end of the list. The cKey argument is also optional and is used to specify a unique value used to identify the image, analogous to a primary key. The oPicture argument is required and must contain an object reference to a picture. This means that you will need to use the LOADPICTURE() function on the graphics file in order to add the image it contains to the control.

You can access the images in the ListImages collection using either the item’s Key or its Index. You need the item’s Index in order to assign an image to a Node in a TreeView or a ListItem in a ListView. However, it may not be possible to identify the correct image without using its Key. So it will not be unusual for you to use code like this to access your images after you have populated the control;
*** Find the image in the imageList
loImage = ThisForm.oImageList.Object.ListImages( <MyImageKey> )

*** And return the index
lnRetVal = loImage.Index
If you have examined the property sheet for the TreeView or ListView controls, you might believe that you can associate it with an ImageList at design time.

Don’t be fooled! This does not work. If you try to do this at design time, you will get a nasty OLE error at run time:

You must bind the ImageList to other controls using code in the Init() of your form. If you try to bind the ImageList in the Init() of the TreeView or ListView that needs it, you run the risk of throwing an error because the ImageList may not be instantiated yet. If you bind the imageList in the Form’s Init() you can be certain that both controls have been instantiated. This line of code is all it takes:
Thisform.oTree.ImageList = This.oImageList.Object
Now, when you add a node to the tree, just specify an index of an image in your image list using this syntax:
oTree.Nodes.Add( relative, relationship, key, text, image, selectedimage)
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform