Solved

Listview vb.net

Posted on 2011-09-13
6
233 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
Independent Software Vendors: 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 500 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

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

761 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