Results 1 to 12 of 12

Thread: [RESOLVED] [2005] Listview SelectedIndexes

  1. #1

    Thread Starter
    Fanatic Member Loraine's Avatar
    Join Date
    Aug 2006
    Location
    8ft. underground
    Posts
    581

    Resolved [RESOLVED] [2005] Listview SelectedIndexes

    In my listview this are the values.

    1 - Dog - 19
    2 - Cat - 2
    3 - Shrew - 5

    How to retrieve the selectedindex in the listview ? If i select the first record the index must be "0" if the second record then the index is "1" if the third the index is "2". i use this method but it gives me a wrong output.

    Code:
    Me.Text = Listview1.SelectedIndexes.ToString
    The output of that is System.Windows.Form.Listview......

  2. #2
    Frenzied Member toecutter's Avatar
    Join Date
    Apr 2006
    Location
    Brisbane, Australia
    Posts
    1,160

    Re: [2005] Listview SelectedIndexes

    Shouldn't
    Me.Text be something like Me.ControlType.text?

  3. #3

    Thread Starter
    Fanatic Member Loraine's Avatar
    Join Date
    Aug 2006
    Location
    8ft. underground
    Posts
    581

    Re: [2005] Listview SelectedIndexes

    Whether i print it on a textbox, other control and a msgbox ... the output is the same

  4. #4
    Frenzied Member toecutter's Avatar
    Join Date
    Apr 2006
    Location
    Brisbane, Australia
    Posts
    1,160

    Re: [2005] Listview SelectedIndexes

    Code:
    txtemailAddress.Text = Me.lsvContacts.SelectedItems(0).SubItems(1).Text
    HTH

  5. #5

    Thread Starter
    Fanatic Member Loraine's Avatar
    Join Date
    Aug 2006
    Location
    8ft. underground
    Posts
    581

    Re: [2005] Listview SelectedIndexes

    but it only retrieve the first record. How about the others ?

  6. #6
    Frenzied Member toecutter's Avatar
    Join Date
    Apr 2006
    Location
    Brisbane, Australia
    Posts
    1,160

    Re: [2005] Listview SelectedIndexes

    Change this SubItems(1) to this SubItems(2), i hope

  7. #7

    Thread Starter
    Fanatic Member Loraine's Avatar
    Join Date
    Aug 2006
    Location
    8ft. underground
    Posts
    581

    Re: [2005] Listview SelectedIndexes

    I use the ListView_SelectedItemChange So how im gonna use the indexes.

    If i use that on a Click event my code and your code would work. But How about on a SelectedItemChanged event ?

  8. #8
    Member
    Join Date
    Jul 2007
    Posts
    38

    Re: [2005] Listview SelectedIndexes

    Try this:

    VB.NET Code:
    1. Dim index As Integer
    2. index = Me.ListView1.FocusedItem.Index

  9. #9
    Member
    Join Date
    Nov 2006
    Posts
    37

    Re: [2005] Listview SelectedIndexes

    this will show a messagebox for each selected item in the listview!

    vb Code:
    1. Dim indexes As ListView.SelectedIndexCollection = ListView1.SelectedIndices
    2.         Dim index, i As Integer
    3.         For Each index In indexes
    4.            msgbox(ListView1.Items(index).SubItems(1).Text)
    5.         Next

  10. #10

    Thread Starter
    Fanatic Member Loraine's Avatar
    Join Date
    Aug 2006
    Location
    8ft. underground
    Posts
    581

    Re: [2005] Listview SelectedIndexes

    Thanks toecutter and D4rkness. Now i know the function of the FocusedItem method of a listview thanks again

  11. #11

    Thread Starter
    Fanatic Member Loraine's Avatar
    Join Date
    Aug 2006
    Location
    8ft. underground
    Posts
    581

    Re: [2005] Listview SelectedIndexes

    Thanks stef-o that was amzing you gave me how to use the selectedindeces im so happy thanks all of you.

  12. #12
    Member
    Join Date
    Jul 2007
    Posts
    38

    Re: [RESOLVED] [2005] Listview SelectedIndexes

    No Problem, glad to help.

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