CTRL C NO GRID?

MESTRE 06/07/2015 16:54:24
#448521
Galera to precisando de um auxílio, dá pra fazer um CTRL c no grid? ou colocar um botão no grid tipo [Ô]Ctrl + C[Ô] e quando der CTRL + V ele colar uma linha
do grid no Excell por exemplo??

to precisando disso e não sei a mínima idéia de como fazer..

por ex tenho os dados do Grid que o pessoal utiliza pra diversas coisas no Excel e no Outlook, teria como eu colocar um botão
pra copiar ai eu dou ctrl v e passa a linha do grid pro excel, outlook e etc??


abraços!
LUIZCOMINO 06/07/2015 17:28:36
#448523
Resposta escolhida
Segue alguns links é bem simples...

http://www.codeproject.com/Articles/36850/DataGridView-Copy-and-Paste

http://www.codeproject.com/Tips/208281/Copy-Paste-in-Datagridview-Control


https://msdn.microsoft.com/pt-br/library/system.windows.forms.datagridview.clipboardcopymode(v=vs.110).aspx?cs-save-lang=1&cs-lang=vb#code-snippet-2





MESTRE 07/07/2015 07:42:28
#448537
Opa obrigado cara deu certinho .. funcionou perfeitamente

vou postar o código como ficou em VB.Net pro pessoal, só coloquei o Copiar no grid que era o que eu estava precisando mesmo

Segue o código abaixo:
  


Private Sub CopyToClipboard()
[ô]Copy to clipboard
Dim dataObj As DataObject = grdRecebimentoPcp.GetClipboardContent()
If dataObj IsNot Nothing Then
Clipboard.SetDataObject(dataObj)
End If
End Sub


Private Function GetStartCell(dgView As DataGridView) As DataGridViewCell
[ô]get the smallest row,column index
If dgView.SelectedCells.Count = 0 Then
Return Nothing
End If

Dim rowIndex As Integer = dgView.Rows.Count - 1
Dim colIndex As Integer = dgView.Columns.Count - 1

For Each dgvCell As DataGridViewCell In dgView.SelectedCells
If dgvCell.RowIndex < rowIndex Then
rowIndex = dgvCell.RowIndex
End If
If dgvCell.ColumnIndex < colIndex Then
colIndex = dgvCell.ColumnIndex
End If
Next

Return dgView(colIndex, rowIndex)
End Function

Private Function ClipBoardValues(clipboardValue As String) As Dictionary(Of Integer, Dictionary(Of Integer, String))
Dim copyValues As New Dictionary(Of Integer, Dictionary(Of Integer, String))()

Dim lines As [String]() = clipboardValue.Split(ControlChars.Lf)

For i As Integer = 0 To lines.Length - 1
copyValues(i) = New Dictionary(Of Integer, String)()
Dim lineContent As [String]() = lines(i).Split(ControlChars.Tab)

[ô]if an empty cell value copied, then set the dictionary with an empty string
[ô]else Set value to dictionary
If lineContent.Length = 0 Then
copyValues(i)(0) = String.Empty
Else
For j As Integer = 0 To lineContent.Length - 1
copyValues(i)(j) = lineContent(j)
Next
End If
Next
Return copyValues
End Function


Private Sub ToolStripMenuItem1_Click(sender As Object, e As EventArgs) Handles ToolStripMenuItem1.Click
CopyToClipboard()
End Sub
Tópico encerrado , respostas não são mais permitidas