Results 1 to 4 of 4

Thread: [RESOLVED] Sort ListView items by checked items at first .

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jul 2017
    Posts
    233

    Resolved [RESOLVED] Sort ListView items by checked items at first .

    I am using VBCCR listview . I want to sort items to display all checked items at the top when the user checks an item or by a press of a button to do the task in one shot .

    Bear in mind that , I want to add the possibility of preserving the checked items even after the listview is re-populated again . I am populating it with a recordset . In the table it reads form , I added a boolean field to save the checked items in the session and then clears all after the form is unloaded . this is not an optimal solution as it costs more overhead especially in large amount of data .

    Also , I want a solution to handle this issue even while not using a recordset to populate the listview .

    My ultimate goal is , The user may search a recordset and gets back fewer list items than the original count , the he selects (checks) some items and want to see them checked again when the search filter changes . I dont use filter method of listview but I mean filtering the recodset by the where clause . So , the listview now populates new items and forgets all checked items the user checked . I need a solution to handle this in populating with recordset or without it.

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Sort ListView items by checked items at first .

    Some ideas

    Database: you'll need to store a value to determine whether checked or not in order to preserve that state for the next time the listview is populated
    -- when populating from database, you can use Order By to sort on checked state (if wanted)

    Other than recordset: you'll likely want to write a file that identifies which items are checked

    Sorting ListView: Create a hidden (zero-width) column that only contains a value when item is checked and cleared when it is unchecked. Sort by that column. Alternate method is to semi-manually sort the listview whenever sorting by checked state is needed. You would first sort by your primary column (whatever that is), if needed. Then you would loop thru the listview from bottom to top
    - when checked listitem found, move it to the top of the list
    -- moving requires insert copied/new item at index #1, then delete the original item
    Last edited by LaVolpe; Nov 2nd, 2019 at 08:05 AM.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jul 2017
    Posts
    233

    Re: Sort ListView items by checked items at first .

    Thanks Lavolpe , brilliant ideas ,I will give them a try today .

    But ,

    Then you would loop thru the listview from bottom to top
    - when checked listitem found, move it to the top of the list
    -- moving requires insert copied/new item at index #1, then delete the original item
    How can I insert an item at a specific index when the listview is already populated .

  4. #4
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Sort ListView items by checked items at first .

    Quote Originally Posted by Hosam AL Dein View Post
    How can I insert an item at a specific index when the listview is already populated .
    The 1st parameter in .ListItems.Add is the optional index
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

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