• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1003
  • Last Modified:

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

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
RobertoFreemano
Asked:
RobertoFreemano
  • 2
2 Solutions
 
nayernaguibCommented:
Replace ListView4.SelectedItems with ListView4.SelectedIndices(0).

_______________

  Nayer Naguib
0
 
mattcarverCommented:
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
 
nayernaguibCommented:
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

Industry Leaders: 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!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now