Solved

VB.Net 2005 Listview Selected Values

Posted on 2007-03-28
5
2,560 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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

737 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