Greycastle Logo

Copy from WPF Datagrid

I´ve used the WPF builtin Datagrid for presenting data easily in like tooling applications and such. Problem is, sooner or later you´ll find yourself wanting to copy that darn data to excel or a mail.

I´ve been struggling with this and found some quite poor ideas on how to do it but thankfully atleast in 4.0 (dont know if its possibly before this) the datagrid has a property called ClipboardCopyMode that allows us to copy the data really simply, with or without headers.

Just use this:

<DataGrid ItemsSource="{Binding Test}" ClipboardCopyMode="IncludeHeader" />

© 2024 Greycastle