ListViews and Context Menus..,
-
Hello experts, I'm trying to have a certain context menu popup when right clicking a ListView's headers, and another context menu popup when right clicking inside of the ListView. Problem is I can't find a way to monitor right clicks on the headers. The ColumnClick event only gets fired when left clicking, and the MouseUp, MouseDown, MouseClick, etc. events are only fired when the mouse is bellow the headers (inside of the ListView). Any suggestions? Thanks in advance, Shy.
-
Hello experts, I'm trying to have a certain context menu popup when right clicking a ListView's headers, and another context menu popup when right clicking inside of the ListView. Problem is I can't find a way to monitor right clicks on the headers. The ColumnClick event only gets fired when left clicking, and the MouseUp, MouseDown, MouseClick, etc. events are only fired when the mouse is bellow the headers (inside of the ListView). Any suggestions? Thanks in advance, Shy.
I've developed a simple workaround... Here it is in case someone finds this post in the future... The
ContextMenuStrip
property of the ListView is initially set to hold the context menu used when clicking the headers. Assuming that the ListView is called "list", the context menu for the headers is called "ctxtHeaders", and the context menu for the body of the list is called "ctxtBody", here is the implementation:private void list_MouseDown(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Right) list.ContextMenuStrip = ctxtBody; } private void ctxtBody_Closing(object sender, ToolStripDropDownClosingEventArgs e) { list.ContextMenuStrip = ctxtHeaders; }
The code is settings the list's context menu to the body's context menu every time it is about to be shown (i.e. when the right mouse botton is clicked). Then, when the context menu is closed, the list's context menu is set to the headers context menu.