Solved - name textbox based on listview

Posted on 2009-12-16
Last Modified: 2012-05-08
hello there,
how can I exactly do this on I used to do this in VB6
name.text = lstMain.Items(1).Text

last.text = lstMain.Items(1).ListSubItems(1).Text

name.text = lstMain.SelectedItem

last.text = lstMain.SelectedItem.SubItems(1)

Open in new window

Question by:XK8ER
    LVL 9

    Accepted Solution

    Like this ?

    Private Sub ListView1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListView1.SelectedIndexChanged
        If ListView1.SelectedItems.Count > 0 Then
          TextBox1.Text = ListView1.SelectedItems(0).Text
          If ListView1.SelectedItems(0).SubItems.Count > 1 Then
            TextBox2.Text = ListView1.SelectedItems(0).SubItems(1).Text
          End If
        End If

      End Sub
    LVL 11

    Assisted Solution

    Make sure you are passing the item index which is available for listview.
    If there are 5 item in listview then you can get items from index 0 to 4 only.

     'To get the item directly

            'If there is any item in listview
            If lstMain.Items.Count > 0 Then
                'Get the first item in name.text
                name.Text = lstMain.Items(0).Text
                'If first item has any subitem
                If lstMain.Items(0).SubItems.Count > 0 Then
                    'get the first sub item in last.text
                    last.Text = lstMain.Items(0).SubItems(0).Text
                End If
            End If

            'To get the selected item

            'If there is any selected row
            If lstMain.SelectedItems.Count > 0 Then
                'Get the first selected row in name.text
                name.Text = lstMain.SelectedItems(0).Text
                'if the selected row has any sub item
                If lstMain.SelectedItems(0).SubItems.Count > 0 Then
                    'get the first sub item of selected item in last.text
                    last.Text = lstMain.SelectedItems(0).SubItems(0).Text
                End If
            End If

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Join & Write a Comment

    Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
    If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    734 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

    25 Experts available now in Live!

    Get 1:1 Help Now