• ListBox selecting without action (Word 2002 SP1)

    Home » Forums » AskWoody support » Productivity software by function » Visual Basic for Applications » ListBox selecting without action (Word 2002 SP1)

    Author
    Topic
    #408809

    This was driving me berserk, but I think I have isolated the cause of this behavior. But I don’t know what to do about it!

    I have a template which immediately opens a form. The form automatically pulls contact info from Outlook and displays it in a list box. The user can then click a name and the info for that person appears in a preview.

    However, more often than not, the listbox displays with a name already selected. (Screen shot below.) I was tearing my hair out until I realized that the name selected is one of two or three in the same place in the list and just happens to fall under where the cursor sat when I double-clicked the template! I tested by selecting the template, moving my cursor off to one side and pressing Enter to run the template. No pre-selection.

    It really looks as if the cursor hovering over where the listbox appears is causing one of these entries to be initially selected. The cursor must be out of the way before the template starts; if you move it after it starts initializing, it still selects an item.

    While I was relieved to discover (or so it seems) the cause of this annoyance, it really sucks in regard to the elegant design of the template… grin

    I haven’t been able to think of anything to do programatically because the selection appears the moment the dialog is finished displaying (it takes about 4 seconds for the listbox to populate).

    Is there anything I can do to keep it from happening in the first place? I can’t control how someone launches the template (no matter how hard I try…).

    Any suggestions will be soooooo appreciated!

    Thanks,
    Kim

    Viewing 1 reply thread
    Author
    Replies
    • #866393

      That’s strange. If I leave my mouse pointer strategically positioned over an area I know will be occupied by a listbox, nothing happens. (Actually, the top item is selected, presumably because I use .SetFocus for the listbox.) Do you have any “mouse event” code that could be causing this and, if so, well, I’m not sure whether you can defeat it in any good way…

      • #866399

        Strange it is.

        There is no mouse event that fires — I’ve tried stepping through the code. My listbox does not have focus — I’ve set focus on a text box that is used as a lookup for the listbox. I have a sub routine that clears any selected items in the list so I tried running that immediately before setting focus in the text box. No go.

        I’ve found that I can set the Locked property to True. This limits the ability to navigate in the listbox itself (so if you have two or three Smiths, you have to keep typing rather than grabbing the slider bar).

        What are the chances of discovering an interesting “feature” like this?

        K

        • #866407

          What if you set .ListIndex = -1 for the list? (In theory, it should already be…) Any chance your mouse driver has some kind of “selection follows the pointer” feature going on?

        • #866408

          What if you set .ListIndex = -1 for the list? (In theory, it should already be…) Any chance your mouse driver has some kind of “selection follows the pointer” feature going on?

        • #866409

          I had a similar situation a few years ago. I found a work-around for it. Tried to find the template, but no luck. It was something like this:
          – create a “dummy” listbox on the form
          – Load the form (without displaying)
          – populate the primary listbox first
          – execute any other code
          – populate the dummy listbox with a few items (all in code)
          – make dummy listbox Invisible
          -set focus to primary listbox
          – Display form

          HTH

          • #866605

            Thank you both for your input,

            Jefferson, I checked my mouse set up. I did have “Automatically move pointer to the default button…” going, but turning it off didn’t solve the problem. I do continue to wonder if this phenom happens on my laptop or if it happens on others. No way of testing at this point.

            Jan, I *think* I follow what you’re suggesting, but I’m not sure it will work either. I tried moving the list box — I put it on the right side of the dialog — filled it then moved it back last thing before displaying the list box — still it selects a line in the box. It’s as if a click or double-click event is firing the moment the form has finished running. But it doesn’t seem to be capturable (ok, now I’m making up words…).

            I didn’t want to hide the form until it’s populated because pulling the contacts from Outlook can take anywhere from 4 to 10 seconds and I don’t want the user confused by nothing happening. However, I will try it to see if this fixes the problem. I could always display a little “Please wait while I work like mad behind the scenes” message…

            So far, my best bet seems to be to lock the list and unlock it with an event such as typing in the lookup box. Will report on Jan’s suggestion.

            Kim hairout

            • #866802

              Kim,

              To clarify: the dummy is a second listbox located where your actual listbox should be. This dummy will “receive” the clicks, if any. Just before showing the form, make dummy invisible and relocate actual listbox. It worked for me back then in Word 97.

            • #867027

              Hey Jan,

              Now that I fully understand it (doh!), I tried it again. The bogus list box did not receive the clicks — I still had an item selected in my final list box. This really makes it seem as if the “phantom click” happens **after** everything is displayed — at least in XP.

              Perhaps Microsoft enhanced it for this later version… bananas

              Thanks again, Kim

            • #867605

              Too bad it doesn’t work for you. bummer
              I’m out of ideas…

            • #867606

              Too bad it doesn’t work for you. bummer
              I’m out of ideas…

            • #867028

              Hey Jan,

              Now that I fully understand it (doh!), I tried it again. The bogus list box did not receive the clicks — I still had an item selected in my final list box. This really makes it seem as if the “phantom click” happens **after** everything is displayed — at least in XP.

              Perhaps Microsoft enhanced it for this later version… bananas

              Thanks again, Kim

            • #866803

              Kim,

              To clarify: the dummy is a second listbox located where your actual listbox should be. This dummy will “receive” the clicks, if any. Just before showing the form, make dummy invisible and relocate actual listbox. It worked for me back then in Word 97.

          • #866606

            Thank you both for your input,

            Jefferson, I checked my mouse set up. I did have “Automatically move pointer to the default button…” going, but turning it off didn’t solve the problem. I do continue to wonder if this phenom happens on my laptop or if it happens on others. No way of testing at this point.

            Jan, I *think* I follow what you’re suggesting, but I’m not sure it will work either. I tried moving the list box — I put it on the right side of the dialog — filled it then moved it back last thing before displaying the list box — still it selects a line in the box. It’s as if a click or double-click event is firing the moment the form has finished running. But it doesn’t seem to be capturable (ok, now I’m making up words…).

            I didn’t want to hide the form until it’s populated because pulling the contacts from Outlook can take anywhere from 4 to 10 seconds and I don’t want the user confused by nothing happening. However, I will try it to see if this fixes the problem. I could always display a little “Please wait while I work like mad behind the scenes” message…

            So far, my best bet seems to be to lock the list and unlock it with an event such as typing in the lookup box. Will report on Jan’s suggestion.

            Kim hairout

        • #866410

          I had a similar situation a few years ago. I found a work-around for it. Tried to find the template, but no luck. It was something like this:
          – create a “dummy” listbox on the form
          – Load the form (without displaying)
          – populate the primary listbox first
          – execute any other code
          – populate the dummy listbox with a few items (all in code)
          – make dummy listbox Invisible
          -set focus to primary listbox
          – Display form

          HTH

      • #866400

        Strange it is.

        There is no mouse event that fires — I’ve tried stepping through the code. My listbox does not have focus — I’ve set focus on a text box that is used as a lookup for the listbox. I have a sub routine that clears any selected items in the list so I tried running that immediately before setting focus in the text box. No go.

        I’ve found that I can set the Locked property to True. This limits the ability to navigate in the listbox itself (so if you have two or three Smiths, you have to keep typing rather than grabbing the slider bar).

        What are the chances of discovering an interesting “feature” like this?

        K

    • #866394

      That’s strange. If I leave my mouse pointer strategically positioned over an area I know will be occupied by a listbox, nothing happens. (Actually, the top item is selected, presumably because I use .SetFocus for the listbox.) Do you have any “mouse event” code that could be causing this and, if so, well, I’m not sure whether you can defeat it in any good way…

    Viewing 1 reply thread
    Reply To: ListBox selecting without action (Word 2002 SP1)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: