Listview的SelectedIndexChanged 问题,在线等
Private Sub ListView1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListView1.SelectedIndexChanged
Try
Me.Label4.Text = Me.ListView1.SelectedItems.Item(0).SubItems(1).Text
Catch
MessageBox.Show(Err.Description, "错误信息", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
End Class
现在的问题是,当我第一次在ListView中单击任意一条记录时都会将那个字段的值赋值给Label4,但当我再一次单击一条记录时就会出错。
出错提示是:指定的参数已超出有效值的范围,指定参数index
谢谢~
[解决办法]
Private Sub ListView1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListView1.SelectedIndexChanged
If Me.ListView1.SelectedItems.Count>0 then
Me.Label4.Text = Me.ListView1.SelectedItems.Item(0).SubItems(1).Text
End if
End Sub
End Class
[解决办法]
If ListView1.SelectedItems.Count> 0 Then
Me.Label4.Text = ListView1.SelectedItems.Item(0).SubItems(0).Text.ToString().Trim() & ListView1.SelectedItems.Item(0).SubItems(1).Text.ToString().Trim()
End If