Learn how to a build a cloud-first strategyRegister Now


vb.net - name textbox based on listview

Posted on 2009-12-16
Medium Priority
Last Modified: 2012-05-08
hello there,
how can I exactly do this on vb.net 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

Accepted Solution

Trideep Patel earned 100 total points
ID: 26069022
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

ROMA CHAUHAN earned 100 total points
ID: 26069110
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

Technology Partners: 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!

Question has a verified solution.

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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Screencast - Getting to Know the Pipeline
Suggested Courses
Course of the Month21 days, 2 hours left to enroll

810 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