Results 1 to 3 of 3

Thread: listview subitem select problem

  1. #1

    Thread Starter
    Fanatic Member Geespot's Avatar
    Join Date
    Oct 2001
    Location
    Birmingham, UK
    Posts
    577

    listview subitem select problem

    Hi,

    i have a listview ( view property set to Details ) fully populated and i want to be able to, when the listview item is changed it to tell me whats in the second column along. To do this i have used..

    VB Code:
    1. Private Sub ListView1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListView1.SelectedIndexChanged
    2.         MsgBox(ListView1.SelectedItems.Item(0).SubItems(1).Text)
    3.     End Sub

    Now if i click on a item in the listview, it popups a msgbox telling whats in the second column along, but if i then choose another item i get the following error

    Additional information: Specified argument was out of the range of valid values.

    can someone please explain what im doing wrong

  2. #2
    Lively Member
    Join Date
    Aug 2001
    Posts
    103
    trap the error to get some better error description


    VB Code:
    1. Private Sub ListView1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListView1.SelectedIndexChanged
    2. on error goto errHandler
    3.         MsgBox(ListView1.SelectedItems.Item(0).SubItems(1).Text)
    4. exit sub
    5. errHandler:
    6. msgbox err.description.tostring
    7.  
    8.     End Sub

    or use try - catch.

    what error description are you getting? sometimes it is more usefull than the error message you receive

  3. #3

    Thread Starter
    Fanatic Member Geespot's Avatar
    Join Date
    Oct 2001
    Location
    Birmingham, UK
    Posts
    577
    thanks for your reply, this is the error i get

    Additional information: Specified argument was out of the range of valid values.

    i didnt think about using try, i will try that, thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width