I am trying to enable copying from a GridView to paste into other programs, but I'm encountering multiple problems.
I have a GridView with MultiSelect = True, SelectionMode = FullRowSelect, and ClipboardCopyMode = EnableAlwaysIncludeHeaderText (though the same problems occurs with EnableWithoutHeaderText).
Problem #1:
When I select a single row, only the current cell is copied. It is pasted as: ColumnHeader<CrLf>CellValue
Expected result: Whole row should be copied.
Problem #2:
When I select multiple rows, copy and paste into another program (I've tried Notepad++ and Excel), the rows are all pasted as a single line. There are tab characters between the cell values, but no newline characters. Instead there is a tab character between the rows. This makes it impossible to paste into Excel -- all values are pasted into a single cell.
Expected result: Tabs between cells, newline between rows.
Problem #3:
To combat the above, I've tried capturing the "Copying" event to roll my own clipboard function:
But the end result is the same as Problem #2 above.
So I put a breakpoint at the end of Sub GridClipboardPrep and guess what? It runs three times! Furthermore, if I paste into Notepad while the program is paused at the breakpoint, it pastes correctly (though without the header row). After the program continues, paste looks like Problem #2 again.
I have a GridView with MultiSelect = True, SelectionMode = FullRowSelect, and ClipboardCopyMode = EnableAlwaysIncludeHeaderText (though the same problems occurs with EnableWithoutHeaderText).
Problem #1:
When I select a single row, only the current cell is copied. It is pasted as: ColumnHeader<CrLf>CellValue
Expected result: Whole row should be copied.
Problem #2:
When I select multiple rows, copy and paste into another program (I've tried Notepad++ and Excel), the rows are all pasted as a single line. There are tab characters between the cell values, but no newline characters. Instead there is a tab character between the rows. This makes it impossible to paste into Excel -- all values are pasted into a single cell.
Expected result: Tabs between cells, newline between rows.
Problem #3:
To combat the above, I've tried capturing the "Copying" event to roll my own clipboard function:
Private Sub GridClipboardPrep(sender As System.Object, e As Telerik.WinControls.UI.GridViewClipboardEventArgs) _ Handles GVComputerSearch.Copying Dim copyStr As String = ConvertSelectedDataToString(sender) Clipboard.SetText(copyStr)End SubPrivate Function ConvertSelectedDataToString(grid As RadGridView) As String Dim strBuild As New System.Text.StringBuilder() Dim row As Integer = 0 While row < grid.SelectedRows.Count Dim cell As Integer = 0 While cell < grid.SelectedRows(row).Cells.Count strBuild.Append(grid.SelectedRows(row).Cells(cell).Value.ToString()) strBuild.Append(vbTab) System.Math.Max(System.Threading.Interlocked.Increment(cell), cell - 1) End While strBuild.Append(System.Environment.NewLine) System.Math.Max(System.Threading.Interlocked.Increment(row), row - 1) End While Return strBuild.ToString()End FunctionBut the end result is the same as Problem #2 above.
So I put a breakpoint at the end of Sub GridClipboardPrep and guess what? It runs three times! Furthermore, if I paste into Notepad while the program is paused at the breakpoint, it pastes correctly (though without the header row). After the program continues, paste looks like Problem #2 again.
