tags:

views:

375

answers:

3

Hi all,

I have a popup containing a ListView. The ListView contains customer names. The popup is openen when a search bar is clicked. The user can enter text in the search bar (TextBox) and the Listview is filterd based on the input.

I want to close the popup whenever it loses focus. However, the default "auto close" behaviour StaysOpen="False" is no good, because it closes the popup everytime someone clicks on the search bar.

How can I close the Popup always when it loses focus, except when the focus goes to the search bar?

+1  A: 

Maybe you can put some hooks on the search text box. When it receives focus, it can open the popup and set StaysOpen = true. When the textbox loses focus, it can set StaysOpen = false on the popup.

vanja.
+1  A: 

Add an event handler to the Leave event (called when focus on the control is lost). In this event handler, you can then check to see if the new item that has focus is the search text box.

if(FormName.ActiveForm.ActiveControl == txtSearchBox)

Then set StaysOpen appropriately based on whether or not the search textbox has focus.

Sticky
+1  A: 

How about:

  1. Forward the focus-lost(Leave, occurs when the control is no longer the active control of the form) event of popup to the parent form
  2. Parent form would, do nothing, if the current focus is on the search bar; else, it would close the the popup.
KMan