473,403 Members | 2,284 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

Retrieve ListView Checked Items

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

Dec 8 '05 #1
2 9908
Hi,

<je**********@hotmail.com> wrote in message
news:11*********************@g49g2000cwa.googlegro ups.com...
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 0> 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
With ListView1
For Each CheckedItem As ListViewItem In .CheckedItems
HdrID = CheckedItem.Text
RDT = CheckedItem.SubItems(0).Text
ToUnit = CheckedItem.SubItems(1).Text
FromUnit = CheckedItem.SubItems(2).Text
' other stuff here
Next
End With
HTH,
Greetings


Thanks for the help!!

Jennifer

Dec 9 '05 #2
Thanks!

Dec 9 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: rob | last post by:
I've been having a problem getting the text associated with checked items in a checkedlistbox control-- this article on MSDN shows how to do it: ...
1
by: Ray Mitchell | last post by:
Hello, In the following code assume that the ListView object "myListView" has been properly created. What I am attempting to do is add a string as a list view item, then read the various string...
7
by: GTi | last post by:
I have a listview that with selected items. But I want to "reselect" items after a refresh. Each items have a uniqe value in the Tag object. After a refresh some new items may be added or removed...
2
by: Eric Jelinek | last post by:
I need a little help here, I have a list view that may contain only a few items. If the size of the listview is larger then what I need to hold the items, and then the user click on whitespace, how...
1
by: Hareth | last post by:
how do I save and open checked and unchecked items in my listview to a txt file this is kinda what I have in mind but doesnt work; I need it for listview w/ checked items and unchecked ...
1
by: sherifffruitfly | last post by:
Hi, I've got a checked list box, and a "go' button on the form. Each item in the checked list box is associated with a program (say notepad, calc, etc.). When the user clicks "go", every item...
4
by: spowel4 | last post by:
My form has a listview populated with the 50 states. When the user checks the checkbox within the listview for a particular state, I need to retrieve which state was checked (i.e. if AZ is checked...
2
by: lenniekuah | last post by:
Hello Friends, I am using C#NET2008, Window Application with LISTVIEW. I encounter an interesting problem while trying to retrieve 2 ListView SubItem column data of ORDERDATE and INVOICE for...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.