0

Well, I'm back. I solved the ListBox problem by using a ContextMenuStripor so I thought!

It comes in perfect, then in a quarter second, two things happen: it disappears, and the TreeNode unselects.

But for that quarter second, it looks perfect! enter image description here

The way that progresses is, I step through the lines of code on the right of the screenshot, 5 lines, then one more F11, and it appears for a 1/4 second, and the TreeNode UNSELECTS.

But here's another interesting thing:

In Design Mode, I clicked the reference to contextMenuStrip1 in the dialog bar beneath the Form, and it appears in the place I dropped it.

enter image description here

Then a click on the TreeView (white as I suppose you know) and it disappears.

Ah, but then I take the mouse and pull the TreeView over to the right, again click the reference below, again the ContextMenuStrip appears, then I click the TreeView, and AGAIN it disappears!

enter image description here

What am I missing, dear friends? Something to do with the focus?

Much obliged for any help.

1 Answers1

0

Got it! I found that responding to Closing could be stopped for study with a break point. Then poked around in the Properties, and tried a few things. Then ultimately googled and found the answer at Do not close ContextMenuStrip on selection of certain items. I added AppFocusChange as not a reason to close.

So far, I'm now able to click the members and select them. Progress!

private void contextMenuStrip1_Closing(object sender, ToolStripDropDownClosingEventArgs e)
    {
         if (e.CloseReason == ToolStripDropDownCloseReason.AppClicked || 
            e.CloseReason == ToolStripDropDownCloseReason.AppFocusChange)
                e.Cancel = true;
    }
     if (e.CloseReason == ToolStripDropDownCloseReason.ItemClicked)
        {
            for (int i = 0; i < 4; i++)
            {
                if (contextMenuStrip1.Items[i].Selected == true)
                {
                    bool res = DoChoice(i);
                    if (res == true) e.Cancel = false;


                }
            }
        }

Then, at DoChoice, I'll invoke the Add or Edit accordingly, and always returna Close to the strip.