Results 1 to 2 of 2

Thread: ListView code to show data in related TextBoxes...

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2014
    Posts
    287

    ListView code to show data in related TextBoxes...

    The following code for 2 List Boxes will show data in related textboxes. How to modify it to use just one ListView which has two columns to achieve the same?

    Code:
    Private Sub ListBox1_MouseClick(sender As Object, e As MouseEventArgs) Handles ListBox1.MouseClick
            Dim lb As New ListBox
            lb = sender
            If lb.SelectedIndex <> -1 Then
                ListBox1.SelectedIndex = lb.SelectedIndex
                ListBox2.SelectedIndex = lb.SelectedIndex
                txtEID.Text = ListBox1.SelectedItem
                txtENM.Text = ListBox2.SelectedItem
            End If
        End Sub

  2. #2

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2014
    Posts
    287

    Re: ListView code to show data in related TextBoxes...

    When I tried something like below. Getting these errors:
    Error 1 Property 'Item' is 'ReadOnly'.
    Error 2 Property 'Item' is 'ReadOnly'.
    Error 3 Value of type 'System.Windows.Forms.ListViewItem' cannot be converted to 'String'.
    Error 4 Value of type 'System.Windows.Forms.ListViewItem' cannot be converted to 'String'.

    The code is:
    Code:
    Private Sub ListView1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListView1.SelectedIndexChanged
            Dim lv As New ListView
            lv = sender
            If lv.SelectedItems.Count > 0 Then
                ListView1.SelectedItems(0) = lv.SelectedItems(0)
                ListView1.SelectedItems(1) = lv.SelectedItems(1)
                txtEID.Text = lv.SelectedItems(0)
                txtENM.Text = lv.SelectedItems(1)
            End If
        End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width