我無法從剪貼板中讀取粘貼的datagridviewrow對象。我想要做的是,當用戶選擇並複製整行時,我會將該行作爲DataObject粘貼到剪貼板中。這工作得很好,但是當我嘗試讀取DataObject時(在用戶單擊粘貼之後),保存在剪貼板中的DataGridViewRow值始終爲Nothing。請幫忙!如何從剪貼板中檢索DataGridView? (它最終在剪貼板中爲空)
這是我用於複製和粘貼的代碼。
Private Sub copyToClipboard()
If DataGridView1.CurrentCell IsNot Nothing AndAlso _
DataGridView1.CurrentCell.Value IsNot Nothing Then
If DataGridView1.SelectedRows.Count = 1 Then
My.Computer.Clipboard.SetData(GetType(DataGridViewRow).ToString, getActiveGrid.SelectedRows(0))
End If
End If
End Sub
Private Sub pasteFromClipboard()
Dim oDataObject As IDataObject = My.Computer.Clipboard.GetDataObject
If oDataObject.GetDataPresent(GetType(DataGridViewRow).ToString) Then
Dim GridRow As DataGridViewRow = _
DirectCast(oDataObject.GetData(GetType(DataGridViewRow).ToString), DataGridViewRow)
' here's the issue. the variable GridRow always has a value of nothing.
End If
End Sub