Adding items to the subitems in a listview in VB 2005

By rieda ·
Hi there

Below is some of my code in VB6 that use to add items to a listview
with subitems:

The listview is called lstvCustomers that gets data from a Access DB

I know how to access data from access and I know how to add the data
in the 1st column

my problem is adding the remaining data in the subitem of VB 2005

VB Version 6 Code:

Set Result = lstvCustomers.ListItems.Add(, , orec!Customer_AccNumber)
With Result
.SubItems(1) = orec!Customer_Name
.SubItems(2) = orec!Customer_Surname
.SubItems(3) = orec!ID_Provided
.SubItems(4) = orec!Customer_Phone
.SubItems(5) = orec!Customer_Fax
.SubItems(6) = orec!Customer_Cell
End With

VB 2005 Code:

Dim strSQL As String = "SELECT * FROM Customers"
Dim cmd As OleDbCommand = New OleDbCommand(strSQL,
Dim objread As OleDbDataReader
objread = cmd.ExecuteReader

While objread.Read
End While


im stuck by the part where i have to add subitems
my listview is designed the same way it was in VB6 with the 7 columns

Please Assist


Mr Rieda Hoosain

This conversation is currently closed to new comments.

Thread display: Collapse - | Expand +

All Answers

Collapse -

Look in the MSDN LIbrary

by alan williams In reply to Adding items to the subit ...

the answer is in the library at

Displaying Subitems in Columns with the Windows Forms ListView Control

you can look online if you don't have your own copy.

Collapse -

One way

by Lionfan1991 In reply to Adding items to the subit ...

There are a number of different ways, but one easy way is below.

While objread.Read
Dim LVI as ListViewItem = lsvCustomers.Items.Add(".")
LVI.Text = objread("Customer_AccNumber")
End While

Note I take advantage of the fact the Add method to the ListViewItemCollection returns a ListViewItem which we can then use to set its properties (Text and SubItems).

Collapse -

Adding items to subitems

by Les Tepper In reply to Adding items to the subit ...

While objread.Read
dim lvItem as New ListViewItem
lvItem.Text = objread("Customer_AccNumber")
End While

Related Discussions

Related Forums