Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Listview vb.net

Posted on 2011-09-13
6
Medium Priority
?
236 Views
Last Modified: 2012-05-12
Hi all,

I have a stupid question that i just cant seem to find the answer to. I use the following code to populate a  list view in vb.net.

What i cant seem to get is i want to double click on a item and only get that value

eg if my list view has 5 coloums and 5 rows i want to be able to get the data from row 5 coloum 4

I hope this makes sense
Me.ListView1.Items.Clear()
        Dim LVI As ListViewItem = Nothing
        Dim cmd As New MySqlCommand
        Dim connect As New MySqlConnection(My.Settings.dnote_dbConnectionString)
Then cmd.CommandText = "SELECT * FROM data"

        cmd.Connection = connect
        connect.Open()
        Dim read As MySqlDataReader
        read = cmd.ExecuteReader
        While read.Read()
            LVI = New ListViewItem(read.GetString(0))
            LVI.SubItems.Add(read.GetString(1))
            LVI.SubItems.Add(read.GetString(2))
            LVI.SubItems.Add(read.GetString(3))
            LVI.SubItems.Add(read.GetString(4))
            LVI.SubItems.Add(read.GetString(5))
            LVI.SubItems.Add(read.GetString(6))
            LVI.SubItems.Add(read.GetString(7))
            ListView1.Items.Add(LVI)
        End While
        read.Close()
        connect.Close()

Open in new window

0
Comment
Question by:frankie_jnr
[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
6 Comments
 
LVL 40
ID: 36529572
React to the SelectedIndexChanged event of the ListView:
Private Sub ListView1_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles ListView1.SelectedIndexChanged
   Debug.WriteLine(ListView1.SelectedItems(0).Text)
End Sub

Open in new window

Note that with a multiple selection, this gives you only the first item. You might want to go further to process multiple selections.
0
 

Author Comment

by:frankie_jnr
ID: 36530868
I did that but it is just not selecting anything or writing anything. Is there some property on the listview that i could have forgotten
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 36532114
Do you mean you want to double on a specific row and specific column?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 15

Expert Comment

by:x77
ID: 36533103
Use ListView.HitText Method.

It Returns as ListViewHitTestInfo instance with ListItem and SubItem.

http://msdn.microsoft.com/en-us/library/system.windows.forms.listviewhittestinfo.aspx
Private Sub lv_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles lv.MouseClick
    Dim info = lv.HitTest(e.X, e.Y)
End Sub

Open in new window

0
 
LVL 15

Accepted Solution

by:
x77 earned 2000 total points
ID: 36533127
For DoubleClick:

    Private Sub lv_MouseDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles lv.MouseDoubleClick
        Dim info = lv.HitTest(e.X, e.Y)
        If info.SubItem IsNot Nothing Then Debug.Print(info.SubItem.Text)
    End Sub
0
 

Author Closing Comment

by:frankie_jnr
ID: 36534202
Thank you very much! Works like a dream!
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

730 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