?
Solved

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

Posted on 2006-10-29
3
Medium Priority
?
910 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
[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
  • 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 60 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 90 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
This article will show how Aten was able to supply easy management and control for Artear's video walls and wide range display configurations of their newsroom.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
Simple Linear Regression

764 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