I want to copy the values from any selected cells in a DataGridView to the clipboard. First of all is there an easy way to do that?
If not what should I use as the Format string in order to set an object(,) to the My.Computer.Clipboard.SetData function?
Public Sub CopySelectedCellsToClipboard(ByVal dgv As DataGridView)
Dim selectedCells As DataGridViewSelectedCellCollection = dgv.SelectedCells
Dim firstCellCoords() As Integer = GetFirstSelectedCellCoOrds(selectedCells)
Dim lastCellCoords() As Integer = GetFirstSelectedCellCoOrds(selectedCells)
Dim copyData(lastCellCoords(0) - firstCellCoords(0), lastCellCoords(1) - firstCellCoords(1)) As Object
For Each cell As DataGridViewCell In selectedCells
copyData(cell.RowIndex - firstCellCoords(0), cell.ColumnIndex - firstCellCoords(1)) = cell.Value
Next
My.Computer.Clipboard.SetData(???Format??? ,copyData)
End Sub
http://msdn2.microsoft.com/en-us/library/dec5efh1.aspx
Roger