Visual Basic 6 Black Book:Image Lists, Tree Views, List Views, And Tab Strips
function GetCookie (name)
{
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen)
{
var j = i + alen;
if (document.cookie.substring(i, j) == arg) {
var end = document.cookie.indexOf (";", j);
if (end == -1)
end = document.cookie.length;
return unescape(document.cookie.substring(j, end));
}
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0) break;
}
return null;
}
var m1='';
var gifstr=GetCookie("UsrType");
if((gifstr!=0 ) && (gifstr!=null)) { m2=gifstr; }
document.write(m1+m2+m3);
Keyword
Title
Author
ISBN
Publisher
Imprint
Brief
Full
Advanced Search
Search Tips
Please Select
-----------
Components
Content Mgt
Certification
Databases
Enterprise Mgt
Fun/Games
Groupware
Hardware
IBM Redbooks
Intranet Dev
Middleware
Multimedia
Networks
OS
Prod Apps
Programming
Security
UI
Web Services
Webmaster
Y2K
-----------
New Titles
-----------
Free Archive
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
function isIE4()
{
return( navigator.appName.indexOf("Microsoft") != -1 && (navigator.appVersion.charAt(0)=='4') );
}
function bookMarkit()
{
var url="http://www.itknowledge.com/PSUser/EWBookMarks.html?url="+window.location+"&isbn=0";
parent.location.href=url;
//var win = window.open(url,"myitk");
//if(!isIE4())
// win.focus();
}
Search this book:
Previous
Table of Contents
Next
Finally, set the list views View property to lvwSmallIcon (= 1) and run the program, as shown in Figure 16.18. You can see the icons weve selected for each item displayed in the list view in that figure. Our code is a success.
Figure 16.18 Using small icons in a list view.
Selecting The View Type In List Views
List view controls support four different views :
lvwIcon0; can be manipulated with the mouse, allowing the user to drag and drop and rearrange objects.
lvwSmallIcon1; allows more ListItem objects to be viewed. Like the icon view, objects can be rearranged by the user.
lvwList2; presents a sorted view of the ListItem objects.
lvwReport3; presents a sorted view, with sub-items, allowing extra information to be displayed.
You set the view type in a list view with its View property, which you can set at design time or runtime.
Lets see an example. Here, well display the various view types in a combo box, Combo1 , and when the user selects one of them, well make that the current view type in the list view, ListView1.
When the form first loads, we place the view types in the combo box:
Private Sub Form_Load()
With Combo1
.AddItem "Icon View"
.AddItem "Small Icon View"
.AddItem "List View"
.AddItem "Report View"
End With
End Sub
Then when the user makes a selection in the combo box, we install the corresponding view in the list view:
Private Sub Combo1_Change()
ListView1.View = Combo1.ListIndex
End Sub
Private Sub Combo1_Click()
ListView1.View = Combo1.ListIndex
End Sub
The result appears in Figure 16.19. Although we can now select all four view types in a list view, note that we havent implemented the last type, the report view, which displays a list of columns. Well take a look at that starting with the next topic in this chapter.
Figure 16.19 Selecting view types in a list view control.
Adding Column Headers To A List View
List views can display lists arranged in columns when you set their View property to lvwReport . Well take a look at using the report view in this and the next topic. Here, well see how to add multiple columns to a list view control.
To add columns to a list view, you just need to add column headers, and you do that with the list views ColumnHeaders collection. For example, heres how we add four columns to a list view, giving each column the caption Field 1, Field 2, and so on:
Private Sub Form_Load()
Dim colHeader As ColumnHeader
Dim intLoopIndex As Integer
For intLoopIndex = 1 To 4
Set colHeader = ListView1.ColumnHeaders.Add()
colHeader.Text = "Field " & intLoopIndex
Next intLoopIndex
End Sub
This code works fine, but each column appears in a default width, which might not be right for the size of your list view. To tailor the columns to your list view control, you can do something like this, where we set the columns Width property:
Private Sub Form_Load()
Dim colHeader As ColumnHeader
Dim intLoopIndex As Integer
For intLoopIndex = 1 To 4
Set colHeader = ListView1.ColumnHeaders.Add()
colHeader.Text = "Field " & intLoopIndex
colHeader.Width = ListView1.Width / 4
Next intLoopIndex
End Sub
After you set the View property of the list view control to lvwReport, the result of this code appears in Figure 16.20 (where weve added a few items to the list view control itself, Items 1 through 3, as well).
Figure 16.20 Supporting column headers in a list view.
Now that were using columns in a list view, how do you add text for each column, item by item? Well look into that next.
Adding Column Fields To A List View
Youve set up a list view and added the items you want to it. Now you want to set the list view up to use columns by setting its View property to lvwReport. Youve added headers to each column (see the previous topic in this chapter)but how do you add text for each item in each column?
You use the ListSubItems collections Add method to add column text to an item. Each ListItem object has a ListSubItems collection, and heres how you use that collections Add method:
ListSubItems.Add [ index ] [, key ] [, text ] [, reporticon ] [, tooltiptext ]
For example, lets say that we add three items to a list view that has four columns. We can add text in each of the columns for each of the three items.
Heres how it works. The first column, or field , holds the items text (set with its Text property). To add text for the following three columns of the first item (well display Field 2 in field 2, Field 3 in field 3, and so on), we use the ListSubItems collections Add method this way:
Private Sub Form_Load()
Dim colHeader As ColumnHeader
Dim intLoopIndex As Integer
For intLoopIndex = 1 To 4 'Label headers
Set colHeader = ListView1.ColumnHeaders.Add()
colHeader.Text = "Field " & intLoopIndex
colHeader.Width = ListView1.Width / 4
Next intLoopIndex
Dim ListItem1 As ListItem
Set ListItem1 = ListView1.ListItems.Add()
ListItem1.Text = "Item 1"
ListItem1.Icon = 1
ListItem1.SmallIcon = 1
ListView1.ListItems(1).ListSubItems.Add , , "Field 2"
ListView1.ListItems(1).ListSubItems.Add , , "Field 3"
ListView1.ListItems(1).ListSubItems.Add , , "Field 4"
...
Previous
Table of Contents
Next
Products | Contact Us | About Us | Privacy | Ad Info | Home
Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc.
All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited.
Wyszukiwarka
Podobne podstrony:
11 (528)528 (2)15 (522)readme (528)Projekt Szczecin 522II CSK 528 06 1I PKN 528 99521 522522,21,artykul528,15,artykul528 533524 528the mentalist 522 hdtv lolwięcej podobnych podstron