Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to copy DataGrid cell value to clipboard

I have a DataGrid. But I want to get focused cell value in CopyingRowClipboardContent event. But e.ClipboardRowContent returns me all selected cells values because of the SelectionUnit. And i must not change selection unit of datagrid. For solving the problem i need to get focused cell column number. Then I will remove all column values from clipboarcContent. How can i get focused cell in CopyingRowClipboardContent event?

like image 846
Farhad Jabiyev Avatar asked Sep 20 '12 11:09

Farhad Jabiyev


2 Answers

Improved version of Farhad's answer

private void DataGrid_CopyingRowClipboardContent(object sender, DataGridRowClipboardEventArgs e)
{
    var currentCell = e.ClipboardRowContent[ dataGrid.CurrentCell.Column.DisplayIndex];
    e.ClipboardRowContent.Clear();
    e.ClipboardRowContent.Add( currentCell );
}
like image 72
Denis Besic Avatar answered Oct 16 '22 09:10

Denis Besic


You can also use the following code in order control clipboard content.

Clipboard.SetText("some value");
like image 20
Hamid Avatar answered Oct 16 '22 09:10

Hamid