Je suis incapable de lire un objet datagridview collé à partir du Presse-papiers. Tout ce que je veux faire est, quand un utilisateur a la ligne entière sélectionnée et copiée, je voudrais coller cette ligne dans le presse-papiers en tant que DataObject. Cela fonctionne très bien mais lorsque j'essaie de lire ce DataObject (après que l'utilisateur clique sur Coller) le DataGridViewRow qui est enregistré dans le Presse-papiers a toujours une valeur de Nothing. S'il vous plaît aider!Comment puis-je récupérer un DataGridView à partir du Presse-papiers? (Il finit par être Null dans le Presse-papiers)
Voici le code que j'utilise pour copier et coller.
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