|
-
Sep 11th, 2006, 08:02 AM
#1
Thread Starter
Addicted Member
[02/03] Retrieving ListView Column values
I have a ListView Control with five columns and four rows. I want to retrieve each column value row-wise. I want to know how to retreive column values by executing a loop.
-
Sep 11th, 2006, 08:20 AM
#2
Re: [02/03] Retrieving ListView Column values
Each row is a ListViewItem. Each item has ListViewSubItems. The Text properties of the subitems contain the strings you see displayed in the control:
VB Code:
For Each item As ListViewItem In myListView.Items
For index As Integer = 0 To myListView.Columns.Count - 1 Step 1
MessageBox.Show(item.SubItems(index).Text)
Next index
Next item
-
Sep 11th, 2006, 08:26 AM
#3
Thread Starter
Addicted Member
Re: [02/03] Retrieving ListView Column values
-
Sep 11th, 2006, 11:30 AM
#4
Thread Starter
Addicted Member
Re: [02/03] Retrieving ListView Column values
jm,
One more thing I want to know is that I want to store column values in an array or something like that so that after the loop finishes, I can retrieve them.
-
Sep 11th, 2006, 06:35 PM
#5
Re: [02/03] Retrieving ListView Column values
I don't get it. You're the one who put the values into the ListView in the first place so why do you need to then retrieve the values from the ListView into an array? If you need the values then you should be keeping them in an array or whatever when you put them in the ListView in the first place.
-
Sep 14th, 2006, 11:36 AM
#6
Thread Starter
Addicted Member
Re: [02/03] Retrieving ListView Column values
jm,
The ListView shows the user the items he has selected. When the user clicks the PRINT button, each row of the ListView gets printed on a different sheet. Actually it is a ticketing software.
I am not storing values in an array because, I want to display the user choices so that he can modify or delete the selection.
-
Sep 14th, 2006, 11:58 AM
#7
Re: [02/03] Retrieving ListView Column values
you can print them right from the listvew control in the loop as jm shows. You don't need to put them in an arry and then print them.
-
Sep 14th, 2006, 12:04 PM
#8
Thread Starter
Addicted Member
Re: [02/03] Retrieving ListView Column values
-
Sep 14th, 2006, 12:31 PM
#9
Re: [02/03] Retrieving ListView Column values
add a "PrintDocument" control in your form and copy this code. I assume you have “PrintDocument1” and “Button1” controls on your form.
VB Code:
Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
Dim x As Integer = 150
Dim y As Integer = 80
Dim fontSize As Single = 12.0
For Each item As ListViewItem In myListView.Items
For index As Integer = 0 To myListView.Columns.Count - 1 Step 1
e.Graphics.DrawString(item.SubItems(index).Text, New Font("Courier", fontSize, FontStyle.Regular), Brushes.Black, x, y)
y = CInt(y + fontSize)
Next index
Next item
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.PrintDocument1.Print()
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|