How can I stop a list-box from scrolling?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • julietbrown
    New Member
    • Jan 2010
    • 99

    How can I stop a list-box from scrolling?

    I have two multi-select list boxes. The user can make a selection from list-box A, and click a button to move the selection into list-box B. The problem is that when list-box A is requeried so that the selection disappears list-box A insists on scrolling down so that it shows only the last items in the list. I really don't want it to scroll at all, but if it must I'd rather it scrolled back to showing the first items, not the last.

    I can't find any methods or properties to allow me to control the scrolling behaviour of a list-box through code at run-time (or any other time, come to that!)

    A further (but less vital, only cosmetic) problem is that if you then scroll list-box A back to the top there are a lot of 'artefact' dividing lines between the list items, which looks very odd and messy.

    I'd be grateful for any light you can shed on these matters.
  • ADezii
    Recognized Expert Expert
    • Apr 2006
    • 8834

    #2
    For the sake of argument, let's say that your List Box is named List1. The following code, placed immediately after after the line that Requeries List1, will automatically go to the top of the List Box and select the 1st item:
    Code:
    Me![List1].ListIndex = 0
    To move to, then remove the Selection Status from that item:
    Code:
    Me![List1].ListIndex = 0
    Me![List1].Selected(0) = False

    Comment

    • julietbrown
      New Member
      • Jan 2010
      • 99

      #3
      Sadly, this works only for non-multiselect list boxes. Multiselect ones don't have this nice simple ListIndex property. But thank you for a having a try at it! I will continue to ponder ...

      Comment

      • MMcCarthy
        Recognized Expert MVP
        • Aug 2006
        • 14387

        #4
        If you requery the listbox A does that solve your problem.

        Comment

        • julietbrown
          New Member
          • Jan 2010
          • 99

          #5
          Nope! I think the problem is that when the items are moved off the list it shuffles through to take them out and move the others up into the gaps, and it does that starting from the top and working all through to the bottom ... where it stops, and stays. What's required is some instruction to tell it to scroll itself back up to the top ... something called ResetList or something, but this method doesn't appear to exist!

          Comment

          • ADezii
            Recognized Expert Expert
            • Apr 2006
            • 8834

            #6
            You could use the API, but here is an approach that should work after the Requery. Granted, it is a little messy, but it do appear to work.
            Code:
            Me![List2].SetFocus
            SendKeys "^{HOME}", True

            Comment

            • MMcCarthy
              Recognized Expert MVP
              • Aug 2006
              • 14387

              #7
              OK this actually works, believe it or not :)

              Code:
              Me.List1.Selected(0) = False

              Comment

              • MMcCarthy
                Recognized Expert MVP
                • Aug 2006
                • 14387

                #8
                @ADezii

                You gave me the idea :) It was the ListIndex part that was causing the problem in your original solution.

                Mary

                Comment

                • ADezii
                  Recognized Expert Expert
                  • Apr 2006
                  • 8834

                  #9
                  Thanks Mary, always there when I need you! (LOL)

                  Comment

                  • julietbrown
                    New Member
                    • Jan 2010
                    • 99

                    #10
                    This seems to have taken off while I was asleep! So far none of the things suggested actually work just as suggested, but I think that's because my code is too complicated and I need to think out more carefully what's actually going on and what needs to go on: currently in danger of desperate hacking!! I've made a note of all the suggestions and am saving them for when I re-attack this problem.

                    Thanks to everybody.

                    Comment

                    • MMcCarthy
                      Recognized Expert MVP
                      • Aug 2006
                      • 14387

                      #11
                      Hi Juliet

                      There is one other thing you could try. That code worked for me without any problems when I had multiselect set to Extended. If your listbox is set to simple change it to extended and see if that makes a difference.

                      Mary

                      Comment

                      • ADezii
                        Recognized Expert Expert
                        • Apr 2006
                        • 8834

                        #12
                        Was the Code inserted 'after' the Requery of the Combo Box and not prior?

                        Comment

                        Working...