Results 1 to 3 of 3

Thread: Sort order by check a list box [RESOLVED]

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 1999
    Location
    México, D.F.
    Posts
    84

    Resolved Sort order by check a list box [RESOLVED]

    Hi vbf:

    I have a list box with the check box option active, and I want to sort order the items alphabetically and by check box activated, like the References menu into VB application, or just show the items that has the check box activated.

    Thanks in advance and regards.
    Last edited by AM LOPEZ; Sep 30th, 2004 at 01:09 PM.
    Angel Maldonado López.
    VB Programmer

  2. #2
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431
    Here's a pretty easy way to do it. Add two hidden listboxes to your form called lstChecked and lstNotChecked. Set the style of lstChecked to sorted. Then if List1 is your current listbox...

    VB Code:
    1. Dim intIndex As Integer
    2.    
    3.     For intIndex = 0 To List1.ListCount - 1
    4.         If List1.Selected(intIndex) Then
    5.             lstChecked.AddItem List1.List(intIndex)
    6.         Else
    7.             lstNotChecked.AddItem List1.List(intIndex)
    8.         End If
    9.     Next
    10.    
    11.     List1.Clear
    12.    
    13.     For intIndex = 0 To lstChecked.ListCount - 1
    14.         List1.AddItem lstChecked.List(intIndex)
    15.         List1.Selected(intIndex) = True
    16.     Next
    17.    
    18.     For intIndex = 0 To lstNotChecked.ListCount - 1
    19.         List1.AddItem lstNotChecked.List(intIndex)
    20.     Next

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jan 1999
    Location
    México, D.F.
    Posts
    84


    Your rigth, it's an easy way to sort the items, I' try to find something like this but I loose my mind, thanks a lot MartinLiss, you solved my problem.

    Regards!!!
    Angel Maldonado López.
    VB Programmer

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