Solved

VB.Net 2005 Listview Selected Values

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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 …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This is a video that shows how the OnPage alerts system integrates into ConnectWise, how a trigger is set, how a page is sent via the trigger, and how the SENT, DELIVERED, READ & REPLIED receipts get entered into the internal tab of the ConnectWise …

919 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

13 Experts available now in Live!

Get 1:1 Help Now