Page 1
Page 2
Page 3
Notice that as in eVB the Fields property
of the Recordset contains all the fields for the current
row position in the database. You can specify a field by
index or by name. The ToString method returns a string representation
of the data, whatever the field type is. Below is an image
of the list created with this code:
A new iteration technique introduced
with .NET is the For Each construct. This can be used with
the Recordset to perform an action for each member row of
the Recordset. The code snippet below is an alternative
to the While loop code shown above:
For Each Tree As FieldCollection In rsTrees
Dim lviNewItem As New ListViewItem
lviNewItem.Text = Tree(Index).ToString
'add tree name as sub-item
Dim strTreeName As String
strTreeName = Tree("TreeName").ToString
lviNewItem.SubItems.Add(strTreeName)
'add item to list
lstTreeList.Items.Add(lviNewItem)
Next
Notice you must specify a name and type
for the current item during iteration. In this example I
have used the descriptive name "Tree", the type
is FieldCollection. You can then refer to the current item
inside the loop using the name given, in this case I retrieve
the TreeName member of the Tree. Note you do not need to
call the MoveNext method using a For Each iteration.
The ListView gives a wide choice of
ways to display your data, for example you can use a field
value to determine the icon which appears with an item.
This screen shows how the Access Viewer
sample displays a different icon for system and user tables
within a database file. This is done by setting the ListItem.ImageIndex
from the TableFlags field in the MSysTables system
table. For outputting a simple grid view of a Recordset,
you can use the DataGrid control which is part of the Compact
Framework.
Previous Page
Next Page