【发布时间】:2010-07-21 17:14:10
【问题描述】:
我无法从剪贴板中读取粘贴的 datagridviewrow 对象。我想要做的是,当用户选择并复制了整行时,我会将该行作为 DataObject 粘贴到剪贴板中。这很好用,但是当我尝试读取该 DataObject(在用户单击粘贴后)时,保存在剪贴板中的 DataGridViewRow 的值始终为 Nothing。请帮忙!
这是我用于复制和粘贴的代码。
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
【问题讨论】:
标签: c# .net vb.net datagridview clipboard