Solved

Listview vb.net

Posted on 2011-09-13
6
223 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
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

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 …
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
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.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

706 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

19 Experts available now in Live!

Get 1:1 Help Now