Solved

VB.Net 2005 Listview Selected Values

Posted on 2007-03-28
5
2,565 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 3

Expert Comment

by:emailrobertwalker
ID: 18812159
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
ID: 18812241
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
ID: 18812315
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 86

Accepted Solution

by:
Mike Tomlinson earned 200 total points
ID: 18812902
   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
ID: 18816802
Appreciate all your help from both of you.
D.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

696 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