Solved

Listview vb.net

Posted on 2011-09-13
6
235 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
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

 
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

Quiz: What Do These Organizations Have In Common?

Hint: Their teams ended up taking quizzes, too.

Question has a verified solution.

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

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
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:…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

632 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