The
.SelectionMode
DataGridView
The only way I've been able to achieve this is by creating a ToolStripMenuItem
wtihin a ContextMenu
control.
First I create a method that overrides the default ClipboardCopyMode
for the DataGridView
:
public void CopyToClipboardWithHeaders(DataGridView _dgv)
{
//Copy to clipboard
_dgv.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableAlwaysIncludeHeaderText;
DataObject dataObj = _dgv.GetClipboardContent();
if (dataObj != null)
Clipboard.SetDataObject(dataObj);
}
Then I call that method and pass it the GridView
in the click event of the ToolStripMenuItem
:
private void copyWithHeadersToolStripMenuItem_Click(Object sender, EventArgs e)
{
CopyToClipboardWithHeaders(dgv);
}
Hope that helps!