Question

Locked

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
orec.MoveNext
End With

=====================================================================
VB 2005 Code:

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

While objread.Read
lsvCustomers.Items.Add(objread("Customer_AccNumber"))
End While

objread.Close()
=====================================================================

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

Thanks

Mr Rieda Hoosain

This conversation is currently closed to new comments.

4 total posts (Page 1 of 1)  
| 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")
LVI.SubItems.Add(objread("Customer_Name")
...
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
lsvCustomers.Items.Add(lvItem)
lvItem.Text = objread("Customer_AccNumber")
lvItem.SubItems.Add(objread("Customer_Name"))
lvItem.SubItems.Add(objread("Customer_SurName"))
.
.
.
End While

Back to Software Forum
4 total posts (Page 1 of 1)  

Software Forums