Results 1 to 9 of 9
  1. #1
    5 Star Lounger kmurdock's Avatar
    Join Date
    Feb 2003
    Location
    Pacific Grove, California, USA
    Posts
    716
    Thanks
    10
    Thanked 34 Times in 28 Posts

    ListBox selecting without action (Word 2002 SP1)

    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... <img src=/S/grin.gif border=0 alt=grin width=15 height=15>

    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

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: ListBox selecting without action (Word 2002 SP

    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...

  3. #3
    5 Star Lounger kmurdock's Avatar
    Join Date
    Feb 2003
    Location
    Pacific Grove, California, USA
    Posts
    716
    Thanks
    10
    Thanked 34 Times in 28 Posts

    Re: ListBox selecting without action (Word 2002 SP

    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

  4. #4
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: ListBox selecting without action (Word 2002 SP

    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?

  5. #5
    4 Star Lounger
    Join Date
    Dec 2003
    Location
    Zoetermeer, Zuid-Holland, Netherlands
    Posts
    559
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: ListBox selecting without action (Word 2002 SP

    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

  6. #6
    5 Star Lounger kmurdock's Avatar
    Join Date
    Feb 2003
    Location
    Pacific Grove, California, USA
    Posts
    716
    Thanks
    10
    Thanked 34 Times in 28 Posts

    Re: ListBox selecting without action (Word 2002 SP

    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 <img src=/S/hairout.gif border=0 alt=hairout width=31 height=23>

  7. #7
    4 Star Lounger
    Join Date
    Dec 2003
    Location
    Zoetermeer, Zuid-Holland, Netherlands
    Posts
    559
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: ListBox selecting without action (Word 2002 SP

    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.

  8. #8
    5 Star Lounger kmurdock's Avatar
    Join Date
    Feb 2003
    Location
    Pacific Grove, California, USA
    Posts
    716
    Thanks
    10
    Thanked 34 Times in 28 Posts

    Re: ListBox selecting without action (Word 2002 SP

    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... <img src=/S/bananas.gif border=0 alt=bananas width=33 height=35>

    Thanks again, Kim

  9. #9
    4 Star Lounger
    Join Date
    Dec 2003
    Location
    Zoetermeer, Zuid-Holland, Netherlands
    Posts
    559
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: ListBox selecting without action (Word 2002 SP

    Too bad it doesn't work for you. <img src=/S/bummer.gif border=0 alt=bummer width=15 height=15>
    I'm out of ideas...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •