Results 1 to 2 of 2
  1. #1
    5 Star Lounger AndrewKKWalker's Avatar
    Join Date
    Apr 2001
    Location
    Cambridge, UK
    Posts
    1,015
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Question STOP RIGHT MOUSE Button selecting items in a MULTISELECT listbox

    Maybe I am being dumb, but more than likely MS are..

    I have a form with a multi select listbox (simple)

    I also have a custom right mouse menu on the list box

    And yes.. it is important I have a list box NOT a subform.

    BUT.. here is the issue

    If you right mouse click over the list box, the current row is selected/deselected, before the menu pops up.

    There is a complication in that the listbox has a header row as well.

    Now, there is a dumb thing Microsoft..
    If there is NO header row, then row 0 of the list box is the first data row, and no data is a listcount of 0
    If there is a header row, then no data is a listcount of -1
    But the number of rows reported includes the header
    The data starts in row 1 NOT row 0.
    OK, I guess sometimes that might be useful.
    Shame there is very little documentation on that though.
    And it is does not appear to behave like a standard VB listbox



    IF I could be sure the user would right click over the data NOT the header, I can fudge a way round this but really
    what I want to know is

    Is there any way that I can stop the RIGHT mouse selecting or deselecting an item, BUT still have the POP UP menu.

    I have a NASTY feeling I know the answer.

    I even tried playing with mouse down event to see if I could work out where it was pressed, BUT the screen size and form location seem to possibly ruin this, and anyway it disables the menu, not the selection.

    I may just have to instruct them NOT to click over the header row !

    Anyone got any ideas??

    ================================================== =============================

    HERE is one way I have got it working, but it REALLY ought to be easier, and it is a bit of a fudge.

    I used the Mouse Down Event.
    Checked the Y position which appears to be stable and relative to the top of the list box (I THINK)
    It varies with font though.

    So my code goes something like

    Code:
    IF Y <= conListBoxHeaderHeight Then
           msgbox "Please right click below the header to see the pop up menu options",vbInformation
    End If
    The message box seems to stop the menus as well, which is an unexpected bonus
    Which means my bodge to stop the right clicked item being changed still works.

    BUT I really want an ELEGANT solution.
    Last edited by AndrewKKWalker; 2014-07-07 at 21:03. Reason: Added a possible solution
    Andrew

  2. Get our unique weekly Newsletter with tips and techniques, how to's and critical updates on Windows 7, Windows 8, Windows XP, Firefox, Internet Explorer, Google, etc. Join our 480,000 subscribers!

    Excel 2013: The Missing Manual

    + Get this BONUS — free!

    Get the most of Excel! Learn about new features, basics of creating a new spreadsheet and using the infamous Ribbon in the first chapter of Excel 2013: The Missing Manual - Subscribe and download Chapter 1 for free!

  3. The Following User Says Thank You to AndrewKKWalker For This Useful Post:

    Azar (2014-09-19)

  4. #2
    5 Star Lounger AndrewKKWalker's Avatar
    Join Date
    Apr 2001
    Location
    Cambridge, UK
    Posts
    1,015
    Thanks
    0
    Thanked 3 Times in 3 Posts
    I GUESS I WAS RIGHT!

    They never considered that a requirement... Homer Good Grief.jpg
    Andrew

Posting Permissions

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