Results 1 to 28 of 28

Thread: ListView Order

  1. #1

    Thread Starter
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808

    ListView Order

    Can someone help me fix this problem, please?

    If you have a look at the attached project you can see that there are two listviews in it, and two buttons.

    If you select any item in any listview and click on the proper button, you'll get a message of which is the item(s) which is/are selected. This is working Ok.

    Now, order the listviews with the column you like most and select any item. When you click on the proper button... you'll see that the left button would state a wrong item as if it was selected. Try several of them and you'll see what I mean.

    How can this be fixed? Thanks in advanced.
    Attached Files Attached Files
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  2. #2
    Hyperactive Member
    Join Date
    Apr 2002
    Location
    UK
    Posts
    506
    If you use .SelectedItem it works fine, but I'm thinking you don't want to use .SelectedItem for multiple selections or something?

  3. #3

    Thread Starter
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    That's right. The ListView i'm actually using (in the real project) accepts multiple selection. However... hang on. It seems I've already corrected. Let me make a couple of more tests and keep you posted.
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  4. #4

    Thread Starter
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808

    Almost there

    I knew I had to test it more....

    This modifications works well with strings only. With numbers and dates (the one I tested) only "works" when it is ascending order.

    Can anyone fix this, please?
    Attached Files Attached Files
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  5. #5
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629
    I haven't the foggiest on the SendMessage but I did find this while reading up on LVM_SORTITEMS

    The comparison function must return a negative value if the first item should precede the second, a positive value if the first item should follow the second, or zero if the two items are equivalent

    I noticed you returned 0, 1, and 2

    Will that help?

  6. #6
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373
    i think i got the answer to this one.. gotta go find it.. brb

  7. #7
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373
    http://support.microsoft.com/default...84&Product=vbb

    NOTE: Using this approach, you will sort the data in the control but not the ListItems collection. Therefore, if you must read the data from the list in sorted order, it is necessary to step through the actual list rather than the ListItems collection.
    this appears to be what is happening

  8. #8

    Thread Starter
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    Kleinma, do you know how to do this??

    NOTE: Using this approach, you will sort the data in the control but not the ListItems collection. Therefore, if you must read the data from the list in sorted order, it is necessary to step through the actual list rather than the ListItems collection.
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  9. #9
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629
    Yup... your selected button displays the numerical part of the collection key. Try it with Msgbox Item.Key in ItemClick() event and compare it with the result of your selcted button

  10. #10

    Thread Starter
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    Originally posted by leinad31
    Yup... your selected button displays the numerical part of the collection key. Try it with Msgbox Item.Key in ItemClick() event and compare it with the result of your selcted button
    Ok, and how would you step through it?
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  11. #11

    Thread Starter
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    anyone?
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  12. #12

    Thread Starter
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    no-one knows??
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  13. #13
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373
    i could never get it to work right... my only thought is there has to be some way to obtain it via API... because i dont see any way to get it via the exposed properties of the listview

  14. #14
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373
    sad thing is I dont think they fixed this in the .NET control either

  15. #15

    Thread Starter
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    Originally posted by kleinma
    sad thing is I dont think they fixed this in the .NET control either
    You've tried this in .NET and it still has issues?
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  16. #16
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373
    well i mean as far as sorting by date or by numeric.. i would have thought by now it would be built into the control to detect the data type and sort correctly... but sadly the .net control still only sorts on strings

    i mean isnt the listview the same damn control used by windows explorer??? that sorts by number and date

  17. #17

    Thread Starter
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    Originally posted by kleinma
    ... i mean isnt the listview the same damn control used by windows explorer??? that sorts by number and date
    Yes, I know what you mean. Probably they use this same code... but they know how to scroll through the actual list instead of the ListItems collections.
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  18. #18
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373
    Originally posted by Mc Brain
    Yes, I know what you mean. Probably they use this same code... but they know how to scroll through the actual list instead of the ListItems collections.
    yeah its kind of bullshiznitz that they tell you in the KB article that you NEED to enumerate through the actual list and not the listitems collection, but dont tell you how to do it

    I don't even know how to access any of the elements of the list without using the listitems collection property... but then again i guess if I did know we would already have an answer

  19. #19
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373
    im working on something... may be what u are looking for

  20. #20

    Thread Starter
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    Please, let me know if you find something.
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  21. #21
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373
    check it
    Attached Files Attached Files

  22. #22

    Thread Starter
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    The problem is that the SelectedItem property is not useful for me. In my project the MultiSelect property is set to true, on purpose. This is to let the user to select several items and, for example, delete them altogether.

    This is why I need this code to work correctly... otherwise, the items that the LV would delete will not be the ones the user's selected but the ones the LV thinks they're selected.
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  23. #23
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373
    it works fine with multi select...

    set the multiselect of the listview to true and put this code in the
    cmdWhatsSel_Click event
    VB Code:
    1. Dim lstItem As ListItem
    2.     For Each lstItem In lvwTest.ListItems
    3.         With lstItem
    4.             If .Selected Then
    5.                 MsgBox .Text & vbCrLf & .SubItems(1) & vbCrLf & .SubItems(2)
    6.             End If
    7.         End With
    8.     Next
    9.     Set lstItem = Nothing

    you can multiselect and then sort, and it will still be the right listitems...

  24. #24

    Thread Starter
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    Originally posted by kleinma
    it works fine with multi select...

    set the multiselect of the listview to true and put this code in the
    cmdWhatsSel_Click event
    VB Code:
    1. Dim lstItem As ListItem
    2.     For Each lstItem In lvwTest.ListItems
    3.         With lstItem
    4.             If .Selected Then
    5.                 MsgBox .Text & vbCrLf & .SubItems(1) & vbCrLf & .SubItems(2)
    6.             End If
    7.         End With
    8.     Next
    9.     Set lstItem = Nothing

    you can multiselect and then sort, and it will still be the right listitems...
    Oh, sorry. I didn't try it because I thought the solution was to use the SelectedItem property. Seems to be working Ok.
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  25. #25
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373
    so does this solve your problem then?

  26. #26

    Thread Starter
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    May I add myself to the 'notes' with the "improves" I've just made to the code and upload it??

    BTW, it's a bit slow if you have too many items on the LV.
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  27. #27
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373
    sure, I have no intentions to copyright it or anything like that... otherwise i wouldn't upload it to the forum

    you can modify anything.. just include me at least in the comments.

    it can be slow with lots of items, because it has to format each item so that it can do an accurate text sort on it... then switch it back to its original form... unfortunatly, this is the only possible way I see to do this.

  28. #28

    Thread Starter
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    Here you go.
    Attached Files Attached Files
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

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