I have a winform datagridview to show customer details and it has a context menu. And I have set the datagridview selection Mode to "FullRowSelect".
What i want is i want to copy the content of the clicked cell content to the clipboard. Not the whole row content. Just the cell content.
I have used the following code to show the Context Menu when it right click on the datagridview and select the row.
private void dgvCusList_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
{
if (e.RowIndex != -1 && e.ColumnIndex != -1)
{
if (e.Button == MouseButtons.Right)
{
DataGridViewCell clickedCell = (sender as DataGridView).Rows[e.RowIndex].Cells[e.ColumnIndex];
this.dgvCusList.CurrentCell = clickedCell;
var relativeMousePosition = dgvCusList.PointToClient(Cursor.Position);
this.cnxtMnuCusResult.Show(dgvCusList, relativeMousePosition);
}
}
}
I want to copy the the cell content to clipboard when i click copy menu item in my context menu.
Please help me to solove this matter.
Thanks in advance. 🙂
Best Answer
If you are having the
SelectionMode
property asFullRowSelect
then copy functionality ofDataGridView
will copy the entire row. Change the value toCellSelect
. Set the below properties to copy only the cell content.If you want to retain the
FullRowSelect
selection mode, then do like below..