上的ContextMenuStrip单击鼠标右键,如果项目选择在列表视图? [英] ContextMenuStrip On RightClick, IF Items Are Selected In Listview?

查看:207
本文介绍了上的ContextMenuStrip单击鼠标右键,如果项目选择在列表视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须附加到列表视图中的ContextMenuStrip,它的伟大的工作,但是我想知道是我可以把它显示出来,只有当一个或多个项目的列表视图中选择。

I have a ContextMenuStrip attached to a list view, and it's working great, but what I'm interested in knowing is how I can have it show up only when one or more items are selected in the listview.

谢谢!

推荐答案

您可以使用的 打开 事件。事件参数有一个取消属性,以便您可以检查您的应用程序的状态,并决定是否有菜单显示(无为),或阻止其显示(通过设置 e.Cancel =真)。然而,像@Grzenio提到,我会觉得更直观,如果成了,我右键单击该项目自动选择。

You could use the Opening event. The event args has a Cancel property so that you can examine the state of your application and decide whether to have the menu show (by doing nothing) or prevent it from showing (by setting e.Cancel = true). However, like @Grzenio mentions, I would find it more intuitive if the item that i right-clicked on became selected automatically.

另一种选择是使用打开事件来填充上下文菜单只有一个禁用的项目,像(不选)左右;这将通知有关为什么命令不可用的用户

Another option would be to use the Opening event to populate the context menu with only one disabled item, with a text like (no item is selected) or so; this would inform the user about why the command is not available.

这篇关于上的ContextMenuStrip单击鼠标右键,如果项目选择在列表视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆