I have a app that is populating a datagridview and have a button to highlight and copy all the data in the datagridview. When I go and paste into excel the first row and first column are blank. Is there a easy switch to not include this?
Here is the code testing with.
Code:Private Sub btnCopyAll_Click(sender As System.Object, e As System.EventArgs) Handles btnCopyAll.Click Dim sClipboard As String = String.Empty dgvResults.SelectAll() dgvResults.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableAlwaysIncludeHeaderText If Me.dgvResults.GetCellCount(DataGridViewElementStates.Selected) > 0 Then Try ' Add the selection to the clipboard. Clipboard.SetDataObject(Me.dgvResults.GetClipboardContent()) ' Replace the text box contents with the clipboard text. sClipboard = sClipboard + vbCrLf + Clipboard.GetText() Catch ex As System.Runtime.InteropServices.ExternalException Throw New Exception(ex.Message, ex.InnerException) MessageBox.Show("The Clipboard could not be accessed.", "Please try again.", MessageBoxButtons.OK, MessageBoxIcon.Information) End Try End If Clipboard.SetText(sClipboard) End Sub




Reply With Quote