The problem again is quite famous. It's amazing that a correct solution "out of the box" has not been googled at once, just common advices - "look here, look there".
Though indeed just coding of a text, putting into the clipboard should be indicated right.
private void dataGridView_FixCopyEncoding_OnKeyUp(object sender, KeyEventArgs e)
{
DataGridView dataGrid = sender as DataGridView;
if (dataGrid != null && (e.KeyCode == Keys.Insert
|| (e.Control && e.KeyCode == Keys.C)))
{
if (dataGrid.GetCellCount(DataGridViewElementStates.Selected) > 0)
{
string content = dataGrid.GetClipboardContent().GetText();
Clipboard.SetText(content, TextDataFormat.UnicodeText);
}
}
}
If somebody wishes to make a little bit more correct of course it is better to inherit and redefine DataGridView.GetClipboardContent().
I was very surprised when saw that on RightCtrl-Insert press two messages come instead of one. The first is e.Control == false && e.KeyCode = LButton | ShiftKey and the second is e.Control == false && e.KeyCode = Insert.
No comments:
Post a Comment