vb.net ListView中使用ContextMenu的例子哪个有?
如题,哪个发下代码看下,不胜感激。谢了
[解决办法]
Private Sub ListView1_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListView1.MouseClick
If e.Button = Windows.Forms.MouseButtons.Right And ListView1.SelectedItems.Count = 1 Then '如果是单击右键并且只有一项选中,则
Dim ContextMenu As New ContextMenuStrip '右键菜单
Dim ContextMenuItem As New ToolStripMenuItem '右键菜单项
ContextMenuItem.Name = "Copy"
ContextMenuItem.Text = "复制查询条件"
ContextMenu.Items.Add(ContextMenuItem)
AddHandler ContextMenuItem.Click, AddressOf Me.ContexMenuItems_Click '为右键菜单项注册事件
ContextMenu.Show(Control.MousePosition)
End If
End Sub
Private Sub ContexMenuItems_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim MenuItem As ToolStripMenuItem = CType(sender, ToolStripMenuItem)
If MenuItem.Name = "Copy" Then
'……
End If
End Sub