Do not close ContextMenuStrip
-
Hello, i have a treeView component where a ContextMenuStrip is already assigned to it (ex. contextP) now, i want to drag a node from one place to another in the treeView. when i do so, i call the DragDrop event which has all my function's according to my needs. in this event, i would like to call a different ContextMenuStrip named contextD. i thought of using
. . . contextD.Show(Point pt); . . . private void contextD_Opening(object sender, CancelEventArgs e) { ToolStripMenuItem itemMove = (ToolStripMenuItem)contextDrag.Items["ctextMoveItem"]; ToolStripMenuItem itemCopy = (ToolStripMenuItem)contextDrag.Items["ctextCopyItem"]; ToolStripMenuItem itemCancel = (ToolStripMenuItem)contextDrag.Items["ctextCancelItem"]; }
but when the opening event has finished, the main code continues, and the contextD is still shown, regardless to my selection. how can i make the contextD to stay on, depending on my selection in the menu to continue my flow (do event's etc.) ? then of course, how to close it when im finished with it ? thanks Eyal -
Hello, i have a treeView component where a ContextMenuStrip is already assigned to it (ex. contextP) now, i want to drag a node from one place to another in the treeView. when i do so, i call the DragDrop event which has all my function's according to my needs. in this event, i would like to call a different ContextMenuStrip named contextD. i thought of using
. . . contextD.Show(Point pt); . . . private void contextD_Opening(object sender, CancelEventArgs e) { ToolStripMenuItem itemMove = (ToolStripMenuItem)contextDrag.Items["ctextMoveItem"]; ToolStripMenuItem itemCopy = (ToolStripMenuItem)contextDrag.Items["ctextCopyItem"]; ToolStripMenuItem itemCancel = (ToolStripMenuItem)contextDrag.Items["ctextCancelItem"]; }
but when the opening event has finished, the main code continues, and the contextD is still shown, regardless to my selection. how can i make the contextD to stay on, depending on my selection in the menu to continue my flow (do event's etc.) ? then of course, how to close it when im finished with it ? thanks EyalHi Eyal, I have a lot of experience working with TreeViews. Reading your description I can't really figure out what the relationship of the ContextMenuStrip and moving/copying/cancelling drag is in relationship to what you are doing with nodes. Are you implying you want to put up a context menu strip during a drag operation : then let the user select move/copy/cancel from the context menu ? If this is correct, would you want to put this context menu up at the moment the drag started (just after the call to 'DoDragDrop) ... or maybe when the drop target has been selected and DragDrop is being executed ? Please describe further what your goal is here. Using key combinations to determine whether a Drag Move or Drag Copy is being done is a fairly standard practice (usually detected in the source's ItemDrag event). And, of course, you have the QueryContinueDrag event to use to allow cancelling in the DragSource's code in response to mouse or key events : [^] best, Bill
"Many : not conversant with mathematical studies, imagine that because it [the Analytical Engine] is to give results in numerical notation, its processes must consequently be arithmetical, numerical, rather than algebraical and analytical. This is an error. The engine can arrange and combine numerical quantities as if they were letters or any other general symbols; and it fact it might bring out its results in algebraical notation, were provisions made accordingly." Ada, Countess Lovelace, 1844
-
Hi Eyal, I have a lot of experience working with TreeViews. Reading your description I can't really figure out what the relationship of the ContextMenuStrip and moving/copying/cancelling drag is in relationship to what you are doing with nodes. Are you implying you want to put up a context menu strip during a drag operation : then let the user select move/copy/cancel from the context menu ? If this is correct, would you want to put this context menu up at the moment the drag started (just after the call to 'DoDragDrop) ... or maybe when the drop target has been selected and DragDrop is being executed ? Please describe further what your goal is here. Using key combinations to determine whether a Drag Move or Drag Copy is being done is a fairly standard practice (usually detected in the source's ItemDrag event). And, of course, you have the QueryContinueDrag event to use to allow cancelling in the DragSource's code in response to mouse or key events : [^] best, Bill
"Many : not conversant with mathematical studies, imagine that because it [the Analytical Engine] is to give results in numerical notation, its processes must consequently be arithmetical, numerical, rather than algebraical and analytical. This is an error. The engine can arrange and combine numerical quantities as if they were letters or any other general symbols; and it fact it might bring out its results in algebraical notation, were provisions made accordingly." Ada, Countess Lovelace, 1844
Hello Bill, thanks for your replay. to be more accurate what i intend to do is after the drop target has been selected, then put up a context menu strip with the relevant options. when the user selects copy for example, invoke the copy event which copies the source to the target.. and if the user selects cancel, do nothing the event's are something i already have in my program, the only thing missing is this context menu strip option the will activate them properly. have i made my self more clear ? thanks a lot Eyal
-
Hello Bill, thanks for your replay. to be more accurate what i intend to do is after the drop target has been selected, then put up a context menu strip with the relevant options. when the user selects copy for example, invoke the copy event which copies the source to the target.. and if the user selects cancel, do nothing the event's are something i already have in my program, the only thing missing is this context menu strip option the will activate them properly. have i made my self more clear ? thanks a lot Eyal
Hi Eyalle, I think there is a "structural problem" here, but I have to disclaimer what I'll say by letting you know I'm working with a 3rd. party WinForms tree control whose behavior may be different than the standard WinForms TreeView, and I don't have time to go back and test against the standard WinForms TreeView. The problem as I see it is the rather unique dynamics of drag and drop : first the control the drag is coming from continues to capture the mouse until Drop time. Yes you can put up a context menu strip, or a menustrip, in the DragDrop of the drop-target control event, and set some global variable by selecting one of its items : the problem seems to be it runs on another thread : it's not modal : it doesn't block the rest of the code running in your DragDrop handler from proceeding : in fact, if you put a Console.WriteLine in your context menu selectItem code to print out your choice : you'll find it's written out after the DragDrop completes. I have one prototype I wrote where I completely bypassed all of the regular WinForms drag and drop : in that prototype I was successful, in doing exactly what you are describing here (and with a much better drag-drop preview image, and a nice option menu that stuck around until you dismissed it). If I have the time I intend to publish that technique here on CP. Perhaps one of our resident "gurus" will "weigh in" here with some wisdom :) best, Bill
"Many : not conversant with mathematical studies, imagine that because it [the Analytical Engine] is to give results in numerical notation, its processes must consequently be arithmetical, numerical, rather than algebraical and analytical. This is an error. The engine can arrange and combine numerical quantities as if they were letters or any other general symbols; and it fact it might bring out its results in algebraical notation, were provisions made accordingly." Ada, Countess Lovelace, 1844
-
Hi Eyalle, I think there is a "structural problem" here, but I have to disclaimer what I'll say by letting you know I'm working with a 3rd. party WinForms tree control whose behavior may be different than the standard WinForms TreeView, and I don't have time to go back and test against the standard WinForms TreeView. The problem as I see it is the rather unique dynamics of drag and drop : first the control the drag is coming from continues to capture the mouse until Drop time. Yes you can put up a context menu strip, or a menustrip, in the DragDrop of the drop-target control event, and set some global variable by selecting one of its items : the problem seems to be it runs on another thread : it's not modal : it doesn't block the rest of the code running in your DragDrop handler from proceeding : in fact, if you put a Console.WriteLine in your context menu selectItem code to print out your choice : you'll find it's written out after the DragDrop completes. I have one prototype I wrote where I completely bypassed all of the regular WinForms drag and drop : in that prototype I was successful, in doing exactly what you are describing here (and with a much better drag-drop preview image, and a nice option menu that stuck around until you dismissed it). If I have the time I intend to publish that technique here on CP. Perhaps one of our resident "gurus" will "weigh in" here with some wisdom :) best, Bill
"Many : not conversant with mathematical studies, imagine that because it [the Analytical Engine] is to give results in numerical notation, its processes must consequently be arithmetical, numerical, rather than algebraical and analytical. This is an error. The engine can arrange and combine numerical quantities as if they were letters or any other general symbols; and it fact it might bring out its results in algebraical notation, were provisions made accordingly." Ada, Countess Lovelace, 1844
-
Hi Bill, Thanks again for you're time. it will be great if you will have the time to post that code, im sure it will help lot's of programmers.. Happy holiday's Eyal
Hi Eyalle, Happy Hanukkah !
eyalle wrote:
it will be great if you will have the time to post that code, im sure it will help lot's of programmers..
It will be a few months before I get to this, probably. Consider the many benefits built into "native" drag-and-drop including (with effort) drag-dropping stuff from one application into another, interacting with the clipboard, the whole DataObject functionality built-in, dropping files or whatever to the desktop, etc. best, Bill
"Many : not conversant with mathematical studies, imagine that because it [the Analytical Engine] is to give results in numerical notation, its processes must consequently be arithmetical, numerical, rather than algebraical and analytical. This is an error. The engine can arrange and combine numerical quantities as if they were letters or any other general symbols; and it fact it might bring out its results in algebraical notation, were provisions made accordingly." Ada, Countess Lovelace, 1844