Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to reference a specific column in a listview. 1

Status
Not open for further replies.

steve728

Programmer
Mar 16, 2003
536
US
Basically I need the right syntax so that I can display the value in the listview's 2nd column:

MessageBox.Show("You selected FieldCode: " & Me.lvMOCApps.Column2)

VS.NET 2003
Steve728
 
Thanks to you, RiverGuy, I'm able to display the appropriate column but the row always defaults to the bottom one. I want to display the column of the ROW I click on. Will you please help me with this also?

Thanks in advance

Steve728
 
In the MouseClick event of your ListView, try

Code:
YourListView.GetItemAt(e.X, e.Y)

This will return the ListViewItem which you clicked on. You might need to alter it to get it to work if you click somewhere else on the row, and not directly on the item.
 
I'm new at this. Please help me with the arguments:

MessageBox.Show("You selected row " & Me.lvMOCApps.GetItemAt(e.X, e.Y))

Thanks
 
The GetItemAt Function returns an Object of Type ListViewItem. The .Show Method of MessageBox accepts a String to display. Therefore, you need to pass a String to it. ListViewItems have various properties of a String Type. You need to use one of those properties to display. For example, to display the text in the second column, change your code to MessageBox.Show("You selected row " & Me.lvMOCApps.GetItemAt(e.X, e.Y).SubItems(1).Text)
 
Thanks Buddy! You really came through! I'm having a blast working with VB.NET after YEARS of work with MS Access/ VBA.
You got two stars.

Steve728
 
On the same subject, Can you help me with the following objective?

For Each itm As ListViewItem In Me.lvDocList.SelectedItems
' I want to use the value inside of the 3rd column
' in this listview.
Something = itm.Text (instead of col 1 I want col 3)
Next

Thanks in advance,

Steve728
 
It doesn't work. Look at the following:

For Each itm As ListViewItem In lvIMGDocsRvcd.SelectedItems
With Me.SqlDeleteDocRcvdAdapter2.DeleteCommand
.Parameters("@ABR_ID").Value = Me.txtABR_ID.Text Works
.Parameters("@DateRcvd").Value = DateValue(itm.Text) Works
.Parameters("@IMGDOC_Code").Value = itm.SubItems(2).Text
The 3rd line doesn't work. Please help.

Tanks,

Steve
 
After stabbing at the keyboard a few hundred times I got the answer:
.Parameters("@IMGDOC_Code").Value = itm.SubItems(2).Text()

Thanks anyway! You always come through.

Steve728
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top