Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

wpf datagrid copy and paste what you see

I am using data grid in wpf, and it has copy and paste by default.

I have a date time column and i used binding and String format to make it show it in the date time format i want.

However, when i copy and paste, the pasted text becomes the unformatted date time.

Is there a way to do a copy a paste on "What you see is what you get?"

Thanks, Kev

Edit: I tried using ClipboardContentBinding, putting same thing as i did in binding. And that didn't work

like image 340
Kev84 Avatar asked Aug 03 '11 18:08

Kev84


1 Answers

DataGrid has a number of clipboard extensibility points you can hook into and see what is going on. The grid itself has a CopyingRowClipboardContent event that apart from having all the needed information in the event arguments has a nice helper method FormatClipboardCellValues(string format). Also each column has a CopyingCellClipboardContent which can be used for your particular data time column needs.

Note: By default DataGrid's bound columns (those deriving from DataGridBoundColumn) will have them ClipboardContentBinding pointing to the Binding property if not specified explicitly.

like image 96
ligaz Avatar answered Oct 04 '22 03:10

ligaz