如何在List.NET中将Listview.SelectedItems复制到剪贴板

时间:2011-11-09 04:57:15

标签: vb.net visual-studio-2010

我想使用ContextMenuStrip右键单击获取Listview.selectedItem的文本并复制到剪贴板

1 个答案:

答案 0 :(得分:0)


首先将ContextmenuStrip添加到Listview

Dim cm As ContextMenuStrip = cms_Listview    
ListView1.ContextMenuStrip = cm

然后只需将ToolStripMenuItem.click事件中的选定列表视图项复制到剪贴板

Private Sub tsmi_copy_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsmi_copy.Click
    If ListView1.SelectedItems.Count = 0 Then Exit Sub
    Clipboard.Clear()
    Clipboard.SetText(ListView1.SelectedItems(0).Text)
End Sub