Results 1 to 3 of 3

Thread: ListView Question

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2002
    Posts
    382

    ListView Question

    I'm confused with .Net's version of the ListView box..

    In VB6, If I wanted to make sure a element in the list was actually selected before working with it, i would just do a..

    If lstbox.SelectedIndex > -1 Then
    ....Do Code...
    End If


    How do I make sure an element in a listview in .Net is selected? If the user doesn't select an item, then it throws an error when I try to retrieve the ListViewItem like so..

    Dim lv As ListViewItem = lstChar.SelectedItems(0)

    I don't even know if this is the correct way to get the selected item from the list. Is there another way to get the text from the selected item in the list?

  2. #2
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    You can check if anything is selected first:
    VB Code:
    1. If lstChar.SelectedItems.Length>0
    2. Dim lv As ListViewItem = lstChar.SelectedItems(0)
    3. End if
    4.  
    5. 'or
    6. If Not lstChar.SelectedItems.Length Is Nothing
    7. Dim lv As ListViewItem = lstChar.SelectedItems(0)
    8. End if

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2002
    Posts
    382
    Thank you Edneeis, Had to change the .Length to .Count but it works great...

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