Results 1 to 4 of 4

Thread: [RESOLVED] Remove Focus From Listbox

  1. #1

    Thread Starter
    Frenzied Member toecutter's Avatar
    Join Date
    Apr 2006
    Location
    Brisbane, Australia
    Posts
    1,160

    Resolved [RESOLVED] Remove Focus From Listbox

    I have 4 Listbox's on a form.

    I can click in all 4 and they maintain focus.

    How can i remove focus from all the Listbox's except the one i have just selected when i select a Listbox?

    I have tried

    Code:
       Me.lstExternalDoors.SelectedIndex = -1
            Me.lstInternalDoors.SelectedIndex = -1
            Me.lstInternalWindows.SelectedIndex = -1
    and

    Code:
       Me.lstExternalDoors.SelectedItem = -1
            Me.lstInternalDoors.SelectedItem = -1
            Me.lstInternalWindows.SelectedItem = -1
    This works but i have to click the item in the listbox twice to give it focus.

    Regards

    toe

  2. #2
    PowerPoster keystone_paul's Avatar
    Join Date
    Nov 2008
    Location
    UK
    Posts
    3,327

    Re: Remove Focus From Listbox

    When you say they all retain the focus - do you mean they all show their selections? That is different from focus - a listbox will retain its selection whether focussed or not. Only one control can have the focus at any one time.

    The best approach depends on what you are trying to achieve, if you are saying that the user must only be able to select one item from the whole form then an approach like the one you describe above would work, but you may need to call the "Focus" method of the listbox clicked after deselecting the entries in the other listboxes.

    If all you want to do is suppress the display of the selected item in the listboxes that aren't selected, you might want to consider switching from using listboxes to listview controls instead. Listviews have a property "HideSelection" which when true (which is the default) hides the selection marker when the control loses the focus.
    Last edited by keystone_paul; Apr 25th, 2009 at 03:18 AM.

  3. #3
    PowerPoster keystone_paul's Avatar
    Join Date
    Nov 2008
    Location
    UK
    Posts
    3,327

    Re: Remove Focus From Listbox

    Another alternative approach if you want the user selection to be mutually exclusive (ie only one item from the entire set of listboxes, would again to switch to using a listview set to details or list view, and set up four groups - this will visually separate the items into four sub-lists within a single list.

    If you want an example fo how to do this just shout!

  4. #4

    Thread Starter
    Frenzied Member toecutter's Avatar
    Join Date
    Apr 2006
    Location
    Brisbane, Australia
    Posts
    1,160

    Re: Remove Focus From Listbox

    Quote Originally Posted by keystone_paul View Post
    When you say they all retain the focus - do you mean they all show their selections?
    Yes selection.

    I forgot you can use a listview with only one column

    Thanks

    toe

Tags for this Thread

Posting Permissions

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



Click Here to Expand Forum to Full Width