VB.Net: Problem Retrieve data from ListView

Please support our VB.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Mar 2006
Posts: 24
Reputation: LennieKuah is an unknown quantity at this point 
Solved Threads: 0
LennieKuah LennieKuah is offline Offline
Newbie Poster

VB.Net: Problem Retrieve data from ListView

 
0
  #1
Feb 8th, 2007
Hi there,

I am having problem trying to retrieve the data from ListView the 2nd time round. It works the first time I clicked on the Line Item and when I clicked on another line item it gave me this error message :-
"Specific argument ws out of the range of valid values. Parameter name : Index

Here are the sample scipts:-

Private Sub ListClient_SelectedIndexChanged( _
ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListClient.SelectedIndexChanged

Dim intIndex As Integer

Try
With ListClient

intIndex = .SelectedIndices(0)

lngPClientId = .Items(intIndex).Text
Me.lblClientId.Text = lngPClientId
txtClientName.Text = .Items(intIndex).SubItems(1).Text
txtAcctMgr.Text = .Items(intIndex).SubItems(2).Text

intIndex = 0
End With

Catch ex As Exception
MessageBox.Show(ex.Message)
End Try

End Sub

Please help me. Thanks

Have a Good Day,

Cheers,
Lennie
Attached Thumbnails
ListView.JPG  
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 121
Reputation: manal is an unknown quantity at this point 
Solved Threads: 17
manal's Avatar
manal manal is offline Offline
Junior Poster

Re: VB.Net: Problem Retrieve data from ListView

 
0
  #2
Feb 10th, 2007
hi ,
When you select the first row there is no problem coz the event fires once ok, but the problem accurse when you select other row coz the event (which is ListView1_SelectedIndexChanged) fires twice once for deselect the first row and the other for select the second row. So the message "Specific argument was out of the range of valid values. Parameter name: Index " show because deselect the first row you chosen. I hope I could explain well :cheesy:

Any way the solution is by adding if statement before the retrieve of the list row information

  1. If ListClient.SelectedItems.Count = 0 Then Exit Sub
  2. Try
  3. With ListClient
  4.  
  5. intIndex = .SelectedIndices(0)
  6.  
  7. lngPClientId = .Items(intIndex).Text
  8. Me.lblClientId.Text = lngPClientId
  9. txtClientName.Text = .Items(intIndex).SubItems(1).Text
  10. txtAcctMgr.Text = .Items(intIndex).SubItems(2).Text
  11.  
  12. intIndex = 0
  13. End With
  14.  
  15. Catch ex As Exception
  16. MessageBox.Show(ex.Message)
  17. End Try
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 24
Reputation: LennieKuah is an unknown quantity at this point 
Solved Threads: 0
LennieKuah LennieKuah is offline Offline
Newbie Poster

Re: VB.Net: Problem Retrieve data from ListView

 
0
  #3
Feb 10th, 2007
Originally Posted by manal View Post
hi ,
When you select the first row there is no problem coz the event fires once ok, but the problem accurse when you select other row coz the event (which is ListView1_SelectedIndexChanged) fires twice once for deselect the first row and the other for select the second row. So the message "Specific argument was out of the range of valid values. Parameter name: Index " show because deselect the first row you chosen. I hope I could explain well :cheesy:

Any way the solution is by adding if statement before the retrieve of the list row information

  1. If ListClient.SelectedItems.Count = 0 Then Exit Sub
  2. Try
  3. With ListClient
  4.  
  5. intIndex = .SelectedIndices(0)
  6.  
  7. lngPClientId = .Items(intIndex).Text
  8. Me.lblClientId.Text = lngPClientId
  9. txtClientName.Text = .Items(intIndex).SubItems(1).Text
  10. txtAcctMgr.Text = .Items(intIndex).SubItems(2).Text
  11.  
  12. intIndex = 0
  13. End With
  14.  
  15. Catch ex As Exception
  16. MessageBox.Show(ex.Message)
  17. End Try
Hi Manal,
Thanks for taking time to explain the situation to me. Now, I understand why I am getting those error message. And also thanks for the sample scripts.

Cheers,
Lennie
Last edited by LennieKuah; Feb 10th, 2007 at 10:30 pm. Reason: typo errors
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC