I am attempting to use the automatic header text enumeration value to copy data from my datagridview. I want to be able to select a single cell without column headers. I want to be able to select a full row or all cells in the grid and include column headers.
msdn says The text values of selected cells can be copied to the Clipboard. Row or column header text is included for rows or columns that contain selected cells only when the DataGridView.SelectionMode property is set to RowHeaderSelect or ColumnHeaderSelect and at least one header is selected.
Using that information I set the datagridview as follows: rowheadersvisible = true, multiselect = true, selectionmode=rowheaderselect, clipboardcopymode = enablewithautoheadertext
In this configuration I get no column header information despite whether I select one cell, one row, or all cells. What else must be done to get the results described in the MSDN description?
As a workaround, I handled the keydown event and am able to manipulate the grid to meet my needs at runtime. I would prefer to learn from someone what I am not doing correctly with the EnableWithAutoHeaderText Enumeration value instead of keeping this code.
Private Sub dgvScanHistory_KeyDown(sender As Object, e As KeyEventArgs) Handles dgvScanHistory.KeyDown
If e.Modifiers = Keys.Control Then
ctrlPressed = True
End If
If e.KeyCode = Keys.C And ctrlPressed Then
'this is a hack because autoinclude header cells isn't working correctly.
If dgvScanHistory.AreAllCellsSelected(True) = True Then
dgvScanHistory.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableAlwaysIncludeHeaderText
Else
dgvScanHistory.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableWithoutHeaderText
End If
Clipboard.SetDataObject(dgvScanHistory.GetClipboardContent())
ctrlPressed = False
End If
End Sub
I want to be able to select a single cell without column headersas it conflicts withI want to be able to select a full row or all cells in the grid and include column headers.. - Bjørn-Roger Kringsjå