7

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

Kev84
  • 827
  • 3
  • 15
  • 26
  • 1
    Where do you paste to? Excel? – Dean Kuga Aug 03 '11 at 18:36
  • 2
    Assuming that you are using ClipboardContentBinding correctly, the clipboard data must be in its correct form. If you are pasting to Excel, excel itself will reformat the incoming string if it, any way, resembles a valid date time format.... so the string you have in clipboard might be in the format you expect, but Excel will anyways change it according to its default paste format settings for date.... you can check this by pasting the clipbaord data in Notepad and verify your date format... it should be in your expected format ... please confirm. – WPF-it Aug 04 '11 at 05:47

1 Answers1

2

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.

ligaz
  • 2,081
  • 13
  • 15