8.19 Using Images in a TreeView

 <  Day Day Up  >  

8.19 Using Images in a TreeView

You want to create and display images in a TreeView control for each item .


Technique

Create an ImageList object as explained in Recipe 8.14, "Using ImageLists in a ListView Control." Associate the ImageList object with a TreeView control by setting the TreeView control's ImageList property. To assign images to the individual TreeNode objects, set the Image property of the TreeNode equal to the index of the image in the ImageList you want to use. You can also use the TreeNode editor by selecting the image from the Image drop-down list. A TreeNode can also display a state image that is displayed when the user selects the tree node. You specify this image using the index of an ImageList and assigning that index to the tree node's SelectedImage property.

If you want all the tree nodes to share the same image, you can specify default images. The ImageIndex property specifies the index of an ImageList object to use as the default image for tree nodes. The SelectedImageIndex property is the default for all tree nodes when the user selects a tree node.

Comments

Recipe 8.14 demonstrates how to add images to a ListView control. The process for a TreeView control is strikingly similar, which is not surprising given the object-oriented nature of .NET. The underlying feature that allows you to create images within .NET controls is another control itself named the ImageList . An ImageList contains a collection of Image objects as well as methods to manipulate the collection and properties used to access information about the images or ImageList itself. Once you add images to the ImageList , you can then assign images to a TreeView control using the index of an image within the ImageList , as described in the "Technique" section.

 <  Day Day Up  >  


Microsoft Visual C# .Net 2003
Microsoft Visual C *. NET 2003 development skills Daquan
ISBN: 7508427505
EAN: 2147483647
Year: 2003
Pages: 440

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net