Results 1 to 7 of 7

Thread: 2 questions on possiblities with ListBox

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 2010
    Posts
    185

    2 questions on possiblities with ListBox

    I don't think you can in the first case, can you have the user being able to control Sorted/Unsorted. I know a day or two ago when I was thinking about it I got an error that made think you can only control Sorted at program time and not at runtime.

    Also, is it possible to 'drag and drop" selections. I would like to be able to drag down the text with the mouse and have that act as the 'selection' when I hit the Enter key and have it move over to List2 or back to List1. In some cases I have a couple hundred entries and don't want any but those on the bottom of the list. It would make things a lot quicker if I could make a drag selection versus doing everything with the keyboard. I do have another idea but this one would be so much nicer.

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

    Re: 2 questions on possiblities with ListBox

    Both questions have "yes" answers with workarounds.

    1) You cannot set the Sorted property during run-time. Therefore, to toggle from unsorted to sorted, you must either manually sort the items or clear the listbox & re-add them. Unsorted is not an issue. The listbox's .AddItem method allows you to dictate which position the new item will be inserted at. This overrides the sort behavior of the listbox

    2) Try searching the forum for: listbox drag. You should find some examples
    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
    Nov 2010
    Posts
    185

    Re: 2 questions on possiblities with ListBox

    Quote Originally Posted by LaVolpe View Post
    Both questions have "yes" answers with workarounds.

    1) You cannot set the Sorted property during run-time. Therefore, to toggle from unsorted to sorted, you must either manually sort the items or clear the listbox & re-add them. Unsorted is not an issue. The listbox's .AddItem method allows you to dictate which position the new item will be inserted at. This overrides the sort behavior of the listbox

    2) Try searching the forum for: listbox drag. You should find some examples
    You would still have to manually sort if you cleared the listbox & re-added them wouldn't you? I know right now whenever I update the listboxes I always do it through Clear and re-add, so that approach isn't a problem, but I would have to first get them sorted wouldn't I? If Sorted = False they would still come out unsorted.

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

    Re: 2 questions on possiblities with ListBox

    You got me backwards
    If the listbox has Sorted=True. Clearing & re-adding effectively re-sorts them. If you want to add new items to the end of a sorted listbox and prevent sorting, then you'd have to use the optional Index parameter of the .AddItem method
    Code:
    List2.AddItem "New Item", List2.ListCount
    If the listbox has Sorted=False, you must always manually sort them.
    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}

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Nov 2010
    Posts
    185

    Re: 2 questions on possiblities with ListBox

    Okay, after typing back a nice reply thinking you didn't understand me I reread youy post again and it hit me. I went and tried it and it works. Now I get the picture. Where's the hammer to the head Smilie...I need it right now.

    I'll do some research on the listbox/drag selection and drop and see what I come up with.

    One down one to go.
    Thanks.

  6. #6
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: 2 questions on possiblities with ListBox

    There's another way around the sorted/unsorted listbox problem and that is to have two listboxes exactly on top of each other, one sorted and the other not, and hide the one you don't need. This may or may not be a better solution but it is workable.

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Nov 2010
    Posts
    185

    Re: 2 questions on possiblities with ListBox

    It should work but LaVolpe idea is grand.

    Code:
    Private Sub Command11_Click()
    
    List1.Clear
    For i = 0 To eFileCounter
        List1.AddItem eUser(i), List1.ListCount
    Next
    
    End Sub
    I did this and it works like a charm. I should easily be able to switch back using another button or change it all over to a checkbox.

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