Solved

double click selected item in ListView to open a form vb.net 2003

Posted on 2006-10-29
3
852 Views
Last Modified: 2008-01-09
Hi Experts,

I've created a FORM which has a BUTTON and a LISTVIEW.  When I click the button, it loads items from a text file into the Listview - . So far so good

column A   column B
data           data2
data           data2

The next step is that if an Item in a ROW is double clicked then I want it to open FORM2. When I inserted code into the Double-click button... I get a 'Select expression cannot be of type' error message. See below:
---------------------
Private Sub ListView4_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListView4.DoubleClick
        Select Case ListView4.SelectedItems
            Case 0
                If frmTwo Is Nothing Then
                    frmTwo = New form
                End If
                frmTwo.Show()
        End Select
--------------------

Can anyone Help.
Cheers
0
Comment
Question by:RobertoFreemano
  • 2
3 Comments
 
LVL 14

Expert Comment

by:nayernaguib
ID: 17830245
Replace ListView4.SelectedItems with ListView4.SelectedIndices(0).

_______________

  Nayer Naguib
0
 
LVL 4

Accepted Solution

by:
mattcarver earned 20 total points
ID: 17834912
I wouldn't put "(0)" at the end since the Roberto is using a Select Case statement.  My assumption is he may want to expand this case statement in the future to support additional listview items.

Here is the corrected code:

-------------------------------------------  cut below here -------------------------------------------

Private Sub ListView4_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListView4.DoubleClick
        Select Case ListView4.SelectedIndices
            Case 0
                If frmTwo Is Nothing Then
                    frmTwo = New form
                End If
                frmTwo.Show()
        End Select
0
 
LVL 14

Assisted Solution

by:nayernaguib
nayernaguib earned 30 total points
ID: 17835428
Actually this code will not even compile; you cannot compare a collection to an integer. Instead, the expression ListView4.SelectedIndices(0) refers to the index of the first selected item. If you need to iterate over all ListView items, you can put the Select block inside a For loop and replace ListView4.SelectedIndices(0) with ListView4.SelectedIndices(i).

_______________

  Nayer Naguib
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
This is an explanation of a simple data model to help parse a JSON feed
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

743 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

11 Experts available now in Live!

Get 1:1 Help Now