locked
LISTVIEW CLICK EVENT

    Question

  •  

    How i code :

     

    I have a list VIEW with 3 items, if i double click item 1 it opens form 2

    double click item 2 it opens form 3

    double click item 3 it opens form 4

     

    How can i code this??

     

    Please help, Thanks

    Sunday, September 16, 2007 10:41 AM

Answers

  • Sorry, quick overlook there. In the case of a ListView, perhaps you could try changing the Select Case to something like:

     

    Code Snippet


    Select
    Case ListView1.Items(ListView1.SelectedIndices.Item(0)).Text.ToString()

     

     

     

    Note: if you allow the user to be able to select more than one item, it will still return the first selected.

    Sunday, September 16, 2007 1:36 PM
  • SickDotNet is right. His code works fine. Thank you for your help!

     

    Code Snippet

    Private Sub ListView1_DoubleClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListView1.DoubleClick

     

            Select Case ListView1.Items(ListView1.SelectedIndices.Item(0)).Text.ToString

                Case "Item1"

                    Dim openForm As New Form2

                    openForm.Show()

                Case "Item2"

                    Dim openForm As New Form3

                    openForm.Show()

                Case "Item3"

                    Dim openForm As New Form4

                    openForm.Show()

                Case Else

                    'Do nothing

     

            End Select

        End Sub

     

    Thursday, September 20, 2007 8:42 AM

All replies

  • You can use the DoubleClick-event of the ListBox. Think of something like:

    Code Snippet

        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            'Create the items:
            ListBox1.Items.Add("Item1")
            ListBox1.Items.Add("Item2")
            ListBox1.Items.Add("Item3")
        End Sub

        Private Sub ListBox1_DoubleClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.DoubleClick

            'Define which item was doubleclicked:
            Select Case ListBox1.SelectedItem.ToString()
                Case "Item1"
                    Dim openForm As New Form1
                    openForm.Show()
                Case "Item2"
                    Dim openForm As New Form2
                    openForm.Show()
                Case "Item3"
                    Dim openForm As New Form3
                    openForm.Show()
                Case Else
                    'do nothing
            End Select

        End Sub


    Let us know if this helps.

    Sunday, September 16, 2007 10:54 AM
  • i have a listVIEW as you can see

     

    Sunday, September 16, 2007 12:41 PM
  • Sorry, quick overlook there. In the case of a ListView, perhaps you could try changing the Select Case to something like:

     

    Code Snippet


    Select
    Case ListView1.Items(ListView1.SelectedIndices.Item(0)).Text.ToString()

     

     

     

    Note: if you allow the user to be able to select more than one item, it will still return the first selected.

    Sunday, September 16, 2007 1:36 PM
  • SickDotNet is right. His code works fine. Thank you for your help!

     

    Code Snippet

    Private Sub ListView1_DoubleClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListView1.DoubleClick

     

            Select Case ListView1.Items(ListView1.SelectedIndices.Item(0)).Text.ToString

                Case "Item1"

                    Dim openForm As New Form2

                    openForm.Show()

                Case "Item2"

                    Dim openForm As New Form3

                    openForm.Show()

                Case "Item3"

                    Dim openForm As New Form4

                    openForm.Show()

                Case Else

                    'Do nothing

     

            End Select

        End Sub

     

    Thursday, September 20, 2007 8:42 AM