|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
how to popup context menuHi,
I am a new bee in C#. (I am a VC++ programmer long time already.) I want to display a context menu in ListView. And the context menu items will be changed during runtime -- it depends on the location which user clicked, for example, over ListItem or not. Now I set an empty contexMenuStrip to ContextMenuStrip of ListView. And add ToolStripItems into this empty contexMenuStrip during "Opening" event of contextMenuStrip. But it does not look correct. Anyone knows what I must do? Best Regards, Michael zhang Hi,
donot not set the ListViews ContextMenuStrip before. show the contextMenu when MouseClick event occurs. ex: private void listView1_MouseClick(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Right) { contextMenuStrip1.Show(listView1, e.Location); } } reference:http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1582449&SiteID=1 Thanks and Regards. Manish Bafna. MCP and MCTS. Show quote "zhanglr" wrote: > Hi, > > I am a new bee in C#. (I am a VC++ programmer long time already.) > > I want to display a context menu in ListView. And the context menu items > will be changed during runtime -- it depends on the location which user > clicked, for example, over ListItem or not. > > Now I set an empty contexMenuStrip to ContextMenuStrip of ListView. And add > ToolStripItems into this empty contexMenuStrip during "Opening" event of > contextMenuStrip. But it does not look correct. > > Anyone knows what I must do? > > Best Regards, > Michael zhang Hi,
First of all thanks for your reply. Secondly, I have tried listView1_MouseClick. But this event only will be fired when I right click on item. And I have done one more test -- using listView_MouseDown and listView_MouseUp with Capture=true. But if I right button down on an item in listView, move the mouse out of the listview (even still in same form) and release the right button. At this time I only receive one event listView_MouseDown. -- it is ok for me. But when I move mouse back to the ListView. A listView_MouseUp event will BE FIRED. So a context menu will be displayed in this case. Any good suggestion? At the end thank you for your reply again. Best Regards, Michael zhang Show quote "Manish Bafna" wrote: > Hi, > donot not set the ListViews ContextMenuStrip before. > show the contextMenu when MouseClick event occurs. > ex: > private void listView1_MouseClick(object sender, MouseEventArgs e) { > > if (e.Button == MouseButtons.Right) { > > contextMenuStrip1.Show(listView1, e.Location); > } > } > reference:http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1582449&SiteID=1 > Thanks and Regards. > Manish Bafna. > MCP and MCTS. > > > > "zhanglr" wrote: > > > Hi, > > > > I am a new bee in C#. (I am a VC++ programmer long time already.) > > > > I want to display a context menu in ListView. And the context menu items > > will be changed during runtime -- it depends on the location which user > > clicked, for example, over ListItem or not. > > > > Now I set an empty contexMenuStrip to ContextMenuStrip of ListView. And add > > ToolStripItems into this empty contexMenuStrip during "Opening" event of > > contextMenuStrip. But it does not look correct. > > > > Anyone knows what I must do? > > > > Best Regards, > > Michael zhang Instead of capturing the appropriate event(s), you may want to consider
simply setting the control's ContextMenu property and let the framework handle its display. See: http://msdn2.microsoft.com/en-us/library/system.windows.forms.control.contextmenu.aspx /ravi --------- zhanglr wrote: Show quote > Hi, > > First of all thanks for your reply. > > Secondly, I have tried listView1_MouseClick. But this event only will be > fired when I right click on item. > > And I have done one more test -- using listView_MouseDown and > listView_MouseUp with Capture=true. But if I right button down on an item in > listView, move the mouse out of the listview (even still in same form) and > release the right button. At this time I only receive one event > listView_MouseDown. -- it is ok for me. But when I move mouse back to the > ListView. A listView_MouseUp event will BE FIRED. So a context menu will be > displayed in this case. > > Any good suggestion? > > At the end thank you for your reply again. > > Best Regards, > Michael zhang > > "Manish Bafna" wrote: > >> Hi, >> donot not set the ListViews ContextMenuStrip before. >> show the contextMenu when MouseClick event occurs. >> ex: >> private void listView1_MouseClick(object sender, MouseEventArgs e) { >> >> if (e.Button == MouseButtons.Right) { >> >> contextMenuStrip1.Show(listView1, e.Location); >> } >> } >> reference:http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1582449&SiteID=1 >> Thanks and Regards. >> Manish Bafna. >> MCP and MCTS. >> >> >> >> "zhanglr" wrote: >> >>> Hi, >>> >>> I am a new bee in C#. (I am a VC++ programmer long time already.) >>> >>> I want to display a context menu in ListView. And the context menu items >>> will be changed during runtime -- it depends on the location which user >>> clicked, for example, over ListItem or not. >>> >>> Now I set an empty contexMenuStrip to ContextMenuStrip of ListView. And add >>> ToolStripItems into this empty contexMenuStrip during "Opening" event of >>> contextMenuStrip. But it does not look correct. >>> >>> Anyone knows what I must do? >>> >>> Best Regards, >>> Michael zhang |
|||||||||||||||||||||||