J
jennifer1970
Hi. I am using VB 2005 Beta 2. I have never used a listview before.
I am used to VB6. So please bear with me - I am trying to learn.
I have a listview and want to be able to get the items from each row
when the row is checked. I am using columns too for formatting
puroses. I found examples of how to add columns and followed them -
they work great. Now I want to go through the items and get the text
for each column in each row. I've tried a number of things, but
nothing is working. Please help?
Here's what I did to add items to the listview:
Do Until rsHdr.EOF
HdrID = rsHdr(0).Value
DateTimeDue = rsHdr(1).Value
FromUnit = rsHdr(2).Value
ToUnit = rsHdr(3).Value
' lstHeader.Items.Add(HdrID & DateTimeDue & FromUnit &
ToUnit)
Dim item1 As New ListViewItem(HdrID, 0)
' Place a check mark next to the item.
item1.Checked = False
item1.SubItems.Add(DateTimeDue)
item1.SubItems.Add(FromUnit)
item1.SubItems.Add(ToUnit)
ListView1.Items.AddRange(New ListViewItem() {item1})
rsHdr.MoveNext()
Loop
(And just fyi.... I know using recordsets is not the properway to do
things in .Net. I will change it when I have time.)
This is what I was trying to retrieve the items. I only get the column
header text, which makes sense I suppose. But how do I get to the item
text and subitem text?
With ListView1
For Each MyIndex As Integer In .CheckedIndices
HdrID = ListView1.Columns(0).Text
RDT = ListView1.Columns(1).Text
ToUnit = ListView1.Columns(2).Text
FromUnit = ListView1.Columns(3).Text
' other stuff here
Next
End With
Thanks for the help!!
Jennifer
I am used to VB6. So please bear with me - I am trying to learn.
I have a listview and want to be able to get the items from each row
when the row is checked. I am using columns too for formatting
puroses. I found examples of how to add columns and followed them -
they work great. Now I want to go through the items and get the text
for each column in each row. I've tried a number of things, but
nothing is working. Please help?
Here's what I did to add items to the listview:
Do Until rsHdr.EOF
HdrID = rsHdr(0).Value
DateTimeDue = rsHdr(1).Value
FromUnit = rsHdr(2).Value
ToUnit = rsHdr(3).Value
' lstHeader.Items.Add(HdrID & DateTimeDue & FromUnit &
ToUnit)
Dim item1 As New ListViewItem(HdrID, 0)
' Place a check mark next to the item.
item1.Checked = False
item1.SubItems.Add(DateTimeDue)
item1.SubItems.Add(FromUnit)
item1.SubItems.Add(ToUnit)
ListView1.Items.AddRange(New ListViewItem() {item1})
rsHdr.MoveNext()
Loop
(And just fyi.... I know using recordsets is not the properway to do
things in .Net. I will change it when I have time.)
This is what I was trying to retrieve the items. I only get the column
header text, which makes sense I suppose. But how do I get to the item
text and subitem text?
With ListView1
For Each MyIndex As Integer In .CheckedIndices
HdrID = ListView1.Columns(0).Text
RDT = ListView1.Columns(1).Text
ToUnit = ListView1.Columns(2).Text
FromUnit = ListView1.Columns(3).Text
' other stuff here
Next
End With
Thanks for the help!!
Jennifer