Results 1 to 4 of 4
  1. #1
    New Lounger
    Join Date
    Feb 2008
    Location
    Beckenham, United Kingdom
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi All

    I have a single select list box in a Word VBA User Form. Is there a way to deselect an item in this sort of list box? I only want users ever to be able to select a single item in the list.

    To explain a little more, clicking the item in the list allows them to go through a process to change the data in the selected item and blocks out other options that would be available if no item were selected. However, a user may select the item and then change their mind, hence the need to be able to de-select it (rather than selecting an alternative item in the list).

    My first thought was to write code to set the list index back to -1 if the user clicked on the selected item in the list. However, as far as I can see, if an item is selected then clicking on it again does not seem to fire any event and therefore there is nothing to hang the code on.

    I could have an extra button on the form to clear the selection but this does not seem very elegant.

    Am I missing something? Any ideas/advice greatly appreciated as ever.

    ArchieD

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    You could add an item with a caption like "(none)" to the list box (preferably at the top of the list), and handle it appropriately.

  3. #3
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,853
    Thanks
    4
    Thanked 259 Times in 239 Posts
    [quote name='ArchieDog' post='770276' date='14-Apr-2009 00:02']Is there a way to deselect an item in this sort of list box? I could have an extra button on the form to clear the selection but this does not seem very elegant[/quote]There needs to be a balance between elegance and usability in coming up with a solution to this problem. From a user's point of view, clicking on the same item again would not normally de-select it so I don't see that as a logical action. I would prefer to see a reset button somewhere on the form that could clear all options - this would be most obvious for the users.

    I had hoped that a more subtle solution would be to allow a Ctrl-Click to clear the list selection but this doesn't work and appears not to have an associated action. You could attach a Double-Click action to the list box since this will run happily and is something that the user may easily stumble across when they want to deselect an entry they selected. If your code on the double-click sets the listindex to -1 then it might be logical and obvious enough to work.
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  4. #4
    New Lounger
    Join Date
    Feb 2008
    Location
    Beckenham, United Kingdom
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi Andrew

    Thanks for your reply. I have decided to go with the reset button as I have used this as a solution to clear a drop down list elsewhere in the form and therefore there is some consistency in this approach. The double-click option worked a treat but, as you pointed out, this is not the way things would normally work and therefore perhaps not as intuitive as it should be.

    I also tried the mouse-down event to run the necessary code to de-select and set the list index value back to -1 when the uses presses Ctrl-Click, but, although it appears to do what I need if I step through it, the item is re-selected again at the last minute. I guess the Click event takes priority.

    Many thanks.

    ArchieD

Posting Permissions

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