|
To access the contents, click the chapter and section titles.
Visual Basic 6 Black Book
(Publisher: The Coriolis Group)
Author(s): Steven Holzner
ISBN: 1576102831
Publication Date: 08/01/98
Chapter 16 Image Lists, Tree Views, List Views, And Tab Strips
- If you need an immediate solution to:
- Adding An Image List To A Form
- Adding Images To Image Lists
- Using The Images In Image Lists
- Setting Image Keys In An Image List
- Adding A Tree View To A Form
- Selecting Tree View Styles
- Adding Nodes To A Tree View
- Adding Subnodes To A Tree View
- Adding Images To A Tree View
- Expanding And Collapsing Nodes (And Setting Node Images To Match)
- Handling Tree View Node Clicks
- Adding A List View To A Form
- Adding Items To A List View
- Adding Icons To List View Items
- Adding Small Icons To List View Items
- Selecting The View Type In List Views
- Adding Column Headers To A List View
- Adding Column Fields To A List View
- Handling List View Item Clicks
- Handling List View Column Header Clicks
- Adding A Tab Strip To A Form
- Inserting Tabs Into A Tab Strip Control
- Setting Tab
- Setting Tab Images
- Using A Tab Strip To Display Other Controls
- Handling Tab Clicks
In Depth
In this chapter, were going to take a look at image list controls and some of the controls that use image lists: tree views, list views, and tab strips. These controls are part of the Windows common controls package and are being used more and more frequently in Windows programs.
Well get an overview of each control before tackling the programming issues. You add all the controls in this chapter to the Visual Basic toolbox by selecting the Project|Components menu item, clicking the Controls tab in the dialog box that opens, selecting the entry marked Windows Common Controls, and clicking on OK to close the Components dialog box.
Image Lists
Image list controls are invisible controls that serve one purpose: to hold images that are used by other controls. Usually, you add images to an image list control at design time, using the Insert Picture button in the controls property pages. You can also add images to an image list at runtime, using the Add method of its internal image collection, ListImages.
To use the images in the image list, you usually associate the image list with a Windows common control (which has an ImageList property). For each item in the common control, such as a tab in a tab strip control, you can then specify either an index into the image lists ListImages collection or an images key value to associate that image with the item.
You can also reach the images in an image list with the ListImages collections Picture property. For example, if you wanted to use an image list with a control thats not a Windows common control, such as a picture box, you can assign the first image in the image control to that picture box this way:
Picture1.Picture = ImageList1.ListImages(1).Picture
The Image List Control tool appears in the Visual Basic toolbox in Figure 16.1 at bottom, on the right.
Figure 16.1 The Image List Control tool.
Tree Views
If youve used the Windows Explorer, youre familiar with tree views. Tree views present data in a hierarchical way, such as the view of directories that appears in the tree view at left in the Windows Explorer, as shown in Figure 16.2.
Figure 16.2 The Windows Explorer.
Trees are composed of cascading branches of nodes , and each node usually consists of an image (set with the Image property) and a label (set with the Text property). Images for the nodes are supplied by an image list control associated with the tree view control.
A node can be expanded or collapsed, depending on whether or not the node has child nodes. At the topmost level are root nodes, and each root node can have any number of child nodes. Each node in a tree is actually a programmable Node object, which belongs to the Nodes collection. As with other collections, each member of the collection has a unique Index and Key property that allows you to access the properties of the node.
The Tree View Control tool is the thirteenth tool down on the right in Figure 16.3.
Figure 16.3 The Tree View Control tool.
List Views
The list view control displays, as its name implies, lists of items. You can see a list view at right in the Windows Explorer in Figure 16.2. There, the list view is displaying a list of files. Each item in a list view control is itself a ListItem object and can have both text and an image associated with it. The ListItem objects are stored in the list views ListItems collection.
List views can display data in four different view modes:
- Icon modeCan be manipulated with the mouse, allowing the user to drag and drop and rearrange objects.
- SmallIcon modeAllows more ListItem objects to be viewed. Like the Icon view mode, objects can be rearranged by the user.
- List modePresents a sorted view of the ListItem objects.
- Report modePresents a sorted view, with sub-items, allowing extra information to be displayed.
The list view in the Windows Explorer in Figure 16.2 is displaying files in Report view mode (which is the only mode that has columns and column headers). In this mode, you add sub-items to each item, and the text in those sub-items will appear under the various column headings.
You usually associate two image list controls with a list view: one to hold the icons for the Icon view mode, and one to hold small icons for the other three modes. The size of the icons you use is determined by the image list control (the available sizes are 16 × 16, 32 × 32, 48 × 48, and Custom).
The List View Control tool is the fourteenth control down on the left in Figure 16.4.
Figure 16.4 The List View Control tool.
Tab Strips
A tab strip control presents the user with a row (or rows) of tabs that acts like the dividers in a notebook or the labels on a group of file folders. Like an increasing number of other controls (such as coolbars and tree views), tab strips represent one of Microsofts attempts to compact data into less and less of the screen (because theres getting to be more and more data). Using tab strips, the user can click a tab and see a whole new panel of data, like opening a file folder. In fact, weve already used tab strips in many parts of this book already to set Visual Basic options or to include ActiveX controls in our programs.
|