Click here to Skip to main content
15,891,253 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
VB
Private Sub lvdisplay_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lvdisplay.SelectedIndexChanged
       Dim sno As String
       TripSheet.Show()
       TripSheet.MdiParent = Home
       sno = lvdisplay.SelectedItems(0).SubItems(0).Text
       TripSheet.cb_Sno.Text = sno
       Call TripSheet.display()
       TripSheet.cb_Sno.Focus()
   End Sub



I used this code for select the item from the list view and display the corresponding records in the form.

First i choose the item from the list view means it displays correctly... Next i choose another item from the list view means i got this error...

Give idea to rectify this..................................
Posted
Comments
Sandeep Mewara 8-Jun-12 2:26am    
Which line? What you say is little difficult to follow, yet check for list or combobox value assignement wherever you have done.

1 solution

As usual: changing the selection causes TWO (in numbers: 2) SelectedIndexChanged events. The first event is fired when the old selection was undone, and no item is selected - lvdisplay.SelectedItems does not contain any elements at this moment, and lvdisplay.SelectedItems(0) does not exist! The second event is fired when the new item is selected.
Your error occurs because your code is executed with the first event, whilst you assume you are at the second event.
Simply check:
if (lvdisplay.SelectedItems.Count > 0)
 
Share this answer
 
Comments
VJ Reddy 8-Jun-12 3:09am    
Good answer. 5!
PunithaSabareeswari 8-Jun-12 5:33am    
Thanks................................

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900