Solved

VB.Net 2005 Listview Selected Values

Posted on 2007-03-28
5
2,536 Views
Last Modified: 2008-01-09
Hi all,
I have a listview in a Windows form.  I want the user to be able to select a row and for me to be able to get the value(s) from that row when they have double clicked it.
Thanks.
0
Comment
Question by:porter416
  • 2
  • 2
5 Comments
 
LVL 3

Expert Comment

by:emailrobertwalker
Comment Utility
To return the value of an Item try this.

Private Sub ListView1_DblClick()
    With ListView1
        MsgBox ListView1.SelectedItem
    End With
End Sub
0
 
LVL 3

Assisted Solution

by:emailrobertwalker
emailrobertwalker earned 50 total points
Comment Utility
Here is the exact code for you ...

Private Sub ListView1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListView1.DoubleClick
        Dim I As Integer
        For I = 0 To ListView1.SelectedItems.Count - 1
            MsgBox(ListView1.SelectedItems(I).Text)
        Next
End Sub
0
 

Author Comment

by:porter416
Comment Utility
Wow.  Thanks for the quick response.  I should have added however, that the view has 3 columns and while I want the user to be able to select the row only, I need the values from the entire row.  How do I do this?  Your code returns the value from the first column only even when i click on the values in the third column.

Thanks again,
D.
0
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 200 total points
Comment Utility
   Private Sub ListView1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListView1.DoubleClick
        If ListView1.SelectedItems.Count > 0 Then
            Dim lvi As ListViewItem = ListView1.SelectedItems(0)
            ' the first item listed is the item in column1...even though it is not a "subitem"
            For Each subItem As ListViewItem.ListViewSubItem In lvi.SubItems
                Debug.Print(subItem.Text)
            Next
        End If
    End Sub
0
 

Author Comment

by:porter416
Comment Utility
Appreciate all your help from both of you.
D.
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now