Subscribe

RSS Feed (xml)

Powered By

Skin Design:
Free Blogger Skins

Powered by Blogger

Get $125 within 24 hours
Enter your email address:
Enter the security code shown:

Adding ListItems, SubItems and ColumnHeaders

Basic functionality of the ListView can be achieved through the object model exposed through the eVB control by simply adding the control as either a reference or a component to a project.
Before you can do much of anything with the ListView control, you have to put data into it. In the Report view, the ListView acts somewhat like a ListBox and somewhat like a grid-type control. It has rows, which are called ListItems or Items. The ListItem is, for all intents and purposes, the base unit of the control. Most manipulation is based on the ListItem and the ListView control maintains a collection of Items.
To add Items to the control, we simply use the Append method of the ListItems collection like this:


ListView1.ListItems.Add ItemIndex, ItemKey, ItemText


When in Report view, the ListView also has columns. The first column always displays the Text property of the ListItem. Each additional column is called a SubItem and each ListItem maintains its own collection of Subitems. The Subitems collection isn't a typical collection, though. It has no Add, Delete or Count methods and it is 1-based, meaning the first SubItem has an index of 1.
To add a SubItem to a ListItem's SubItems collection, you simply set the SubItem Text like this:


ListView1.ListItems(ItemIndex).SubItems(SubIndex) = "My SubItem"


The ListItem's Append method returns a reference to the appended ListItem, making further manipulation of the ListItem (and it's Subitems collection) simpler. LVTutorial uses a ListView with two SubItems, and it uses a single method call to add both the ListItem and SubItem at the same time as shown in Listing 1. Like most collections, the Key and Index properties of the ListItems are optional and by not providing them, default values will be provided when they are added.


Adding a ListView ListItem and two SubItems using the object model.


Public Sub COMAddListItem(ItemText As String, _
SubItem1 As String, _
SubItem2 As String)

Dim MyItem As ListItem
' add the list item
Set MyItem = lvwMain.ListItems.Add(, , ItemText)
' set its subitems
MyItem.SubItems(1) = SubItem1
MyItem.SubItems(2) = SubItem2
End Sub


This way, adding a ListItem and its SubItems can be achieved with a single call to COMAddListItem.
It is not very intuitive, but it is crucial to know that each SubItem must also have a column "allocated" in the ListView so it can be displayed. Just adding SubItems to the ListItem will not make them visible. To make the SubItems visible, you must add to the ListView's ColumnHeaders collection.
To make things slightly more confusing, ListItems can be shown without any ColumnHeaders, but viewing any SubItems requires adding at least two ColumnHeaders - one for the ListItem and one for the SubItem. ColumnHeaders are added like this:


ListView1.ColumnHeaders.Add Index, Key, HeaderText


The first ColumnHeader is the header above the ListItem text and each subsequent ColumnHeader corresponds to a SubItem.
LVTutorial has a single method, shown in Listing 2, that adds all of the necessary ColumnHeaders and then adds four ListItems and their SubItems called COMPopulate.

Populating the ListView using the object model.


Public Sub COMPopulate()
' clear the listview
lvwMain.ListItems.Clear
lvwMain.ColumnHeaders.Clear
' Add headers
' you must have as many headers as you have columns
lvwMain.ColumnHeaders.Add , , "Name"
lvwMain.ColumnHeaders.Add , , "Title"
lvwMain.ColumnHeaders.Add , , "Status"

' add data rows
COMAddListItem "Homer", "Safety Inspector", "Full Time"
COMAddListItem "Montgomery", "Tyrant", "Full Time"
COMAddListItem "Carl", "League Supervisor", "Part Time"
COMAddListItem "Lenny", "Core Maintenace", "Part Time"
End Sub


Like the ListItems, we allow the default Key and Index properties of the ColumnHeaders to be allotted by the system when we add them.

JOBGOLDS

Related Link :

1. AFILIATE

2. Browsing dibayar $ Dollar $
a.
ClixSense
b. Bux.to

3. Note book driver acer :
a. TravelMate
b. Extensa
c. Aspire
d. Acer Note
e. Nouvo