944,057 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Unsolved
  • Views: 13745
  • VB.NET RSS
Feb 8th, 2007
0

VB.Net: Problem Retrieve data from ListView

Expand Post »
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
Click image for larger version

Name:	ListView.JPG
Views:	182
Size:	31.6 KB
ID:	2802  
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
LennieKuah is offline Offline
47 posts
since Mar 2006
Feb 10th, 2007
0

Re: VB.Net: Problem Retrieve data from ListView

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

VB.NET Syntax (Toggle Plain Text)
  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
Reputation Points: 37
Solved Threads: 17
Junior Poster
manal is offline Offline
122 posts
since Mar 2006
Feb 10th, 2007
0

Re: VB.Net: Problem Retrieve data from ListView

Click to Expand / Collapse  Quote originally posted by manal ...
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

VB.NET Syntax (Toggle Plain Text)
  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
Reputation Points: 10
Solved Threads: 0
Light Poster
LennieKuah is offline Offline
47 posts
since Mar 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: defeated
Next Thread in VB.NET Forum Timeline: Project Help





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC