Ctrl + c in edit mode DataGridViewCell copies the entire row

I have a datagrid that has one column with text that I would like to allow users to copy text from. I set up the routines to be able to copy the whole cell or row, but I am having trouble editing the cell and typing CTRL + C.

This is the code that I use to enable cell editing. Inside, I can select the text and right-click it to copy. This works fine, if I selected the text and typed CTRL + C, which then copies the line and not the selected text.

I do not want to create my own class, and if this is not possible, I will just leave it as it is.

private void dataGridView1_CellLeave(object sender, DataGridViewCellEventArgs e)
{
    if (dataGridView1.EditingControl == null ||
    dataGridView1.CurrentCell.EditType != typeof (DataGridViewTextBoxEditingControl))
    return;
    dataGridView1.CancelEdit();
    dataGridView1.EndEdit();
}

private void dataGridView1_CellEnter(object sender, DataGridViewCellEventArgs e)
{
    if (dataGridView1.CurrentCell.EditType == typeof(DataGridViewTextBoxEditingControl))
    {
    dataGridView1.BeginEdit(false);
    }
}
+3
source share
2

SelectionMode FullRowSelect, , . CellSelect. CTRL + C.

dataGridView1.SelectionMode = DataGridViewSelectionMode.CellSelect;
dataGridView1.MultiSelect = false;
+2

, , . DataGridViewSelectionMode.FullRowSelect CellSelect. , :

datagridview1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
datagridview1.ClipboardCopyMode = DataGridViewClipboardCopyMode.Disable;
datagridview1.MultiSelect = false;

, ClipboardCopyMode , - MS Windows. ctrl-C, "" .
-- , .NET, . Visual Studio 2013,.NET 4.5 Windows 7.

: / /. . - .

, :

datagridview1.EditMode = DataGridViewEditMode.EditProgrammatically;
datagridview1.EnableHeadersVisualStyles = false;
datagridview1.RowHeadersVisible = false;
+5

All Articles