Get selected item from listview and change the color of selected item

时间:2017-04-10 03:24:27

标签: vb.net listview

User will select one of the person in the listview to assign as a Team Leader, and the selected item will change to specific color.

Below is my coding so far, but I got an error:

InvalidArgument=Value of '1' is not valid for 'index'.

listview table

 Private Sub lvLBSkillsetSEL_DoubleClick(sender As Object, e As EventArgs) Handles lvLBSkillsetSEL.DoubleClick
        If lvLBSkillsetSEL.SelectedItems.Count < 1 Then
            MessageBox.Show("Please select a Team Leader.", Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            Exit Sub
        End If

        Dim _strCLID As ListViewItem
        Dim _strCLName As ListViewItem
        Dim _reply As Integer
        Dim bSkip As Boolean = False


        'Get CLID from selected listview
        With lvLBSkillsetSEL.SelectedItems
            If .Count > 0 Then
                _strCLID = .Item(0)
                _strCLName = .Item(1)

                _reply = _
                            MsgBox("You've choosen " & _strCLName.Text & " as their Team Leader." & vbLf & _
                                   "" & vbLf & vbLf & _
                                   String.Format("Labour: {0} | {1}", _strCLID.Text, _strCLName.Text), _
                                   MsgBoxStyle.YesNo + MsgBoxStyle.Exclamation, _
                                   Application.ProductName)

                If _reply = MsgBoxResult.No Then
                    Exit Sub
                Else
                    bSkip = True

                End If
            Else
                Exit Sub
            End If
        End With
End Sub

0 个答案:

没有答案