3

In windows forms, if I create a simple DataGridView control with couple of rows and columns, and then set the SelectionMode property to FullRowSelect, I get strange behaviour with the clipboard's copy function:

When a row is selected and user hits ctrl-c, the full row is copied to the clipboard with \t characters between cells, as expected.

When a single cell is double-clicked and edited by user, and inside that cell user selects a portion of a text and hits ctrl-c, STILL the whole row is copied, and not the portion of the selected text!

As a workaround i tried to do the clipboard copy on keydown event, but the event is not fired when editing control is in edit mode.

Any suggestions?

Jaska
  • 1,412
  • 1
  • 18
  • 39

1 Answers1

7

as workarround:

disable the clipboard copy when editing

  private void dataGridView1_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
    {
        this.dataGridView1.ClipboardCopyMode = DataGridViewClipboardCopyMode.Disable;
    }

    private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
    {
        this.dataGridView1.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableWithoutHeaderText;
    }
codeteq
  • 1,502
  • 7
  • 13