Solved

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

Posted on 2006-10-29
3
863 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

A short article about problems I had with the new location API and permissions in Marshmallow
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
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 …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

770 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