views:

88

answers:

0

I have the following setup:

1- A ToolStripDropDownButton with a ToolStripDropDown that contains a CustomUserControl that contains a ListView.

2- The ListView has a ContextMenuStrip associated to it.

As a solution for this question, my code works like so:

(psuedocode)
    if ListView RightClicked
       ToolStripDropDown.AutoClose = false;
       ShowContextMenuStrip

    In ContextMenuStripClosing
       ToolStripDropDown.AutoClose = true;
       if ListView not Focused || CloseReason == ItemClicked
           ToolStripDropDown.Close();

The ToolStripDropDown gets dismissed in every manner that it would if I had never monkeyed with the AutoClose property except for one. If I right-click on the ListView, the ContextMenuStrip gets displayed correctly. Then, if I click in the ListView, the ContextMenuStrip is dismissed correctly, and the ToolStripDropDown stays visible as I desire. However, if I click into the application, the ToolStripDropDown does not AutoClose as it should. If I click into the application without displaying the ContextMenuStrip, the ToolStripDropDown auto closes correctly.

Any ideas on what I might be missing here?

For Hans:

protected void ListViewClicked(Object sender, MouseEventArgs e)
{
    if(e.Button == MouseButtons.Right)
    {
        _tempToolStripDropDown.AutoClose = false;
    }
}

protected void ContextStripClosing(Object sender, ToolStripDropDownClosingEventArgs e)
{
    _tempToolStripDropDown.AutoClose = true;
    if(!_tempListView.Focused || e.CloseReason == ToolStripDropDownCloseReason.ItemClicked)
    {
        _tempToolStripDropDown.Close();
    }
}