2011-11-09 66 views
0

我想用剪貼板的ContextMenuStrip單擊鼠標右鍵獲得Listview.selectedItem的文本複製到剪貼板如何複製Listview.SelectedItems在VB.NET

+0

私人小組Copy_ToolStripMenu Item_Click(ByVal sender As System.Object,ByVal e As System.EventArgs)Handles Copy_ToolStripMenuItem.Click Dim A As String = ListView1.FocusedItem.Text Clipboard.SetText(A) End Sub – AGA

回答

0


第一你的ContextMenuStrip添加到您的列表視圖

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