There's a nice article here for copying to Excel via the Clipboard (http://forums.infragistics.com/wpf/articles/xamdatagrid-copying-to-excel-via-the-clipboard.aspx).
The example clearly demonstrates copying a single cell, range of cells, or selected records. What I'm wondering is if anyone knows of a way to easily allow the user to select all cells for all records in the grid. I'm looking for something like a click in the upper left corner of the grid.
Thanks,
Steve
Hello Steve,
Basically this example copying all the cells of the selected records in the XamDataGrid.
If you want to export the whole grid, not just the selected cells, you can use this article also by Andrew Flick - http://forums.infragistics.com/wpf/articles/exporting-the-xamdatagrid-to-excel.aspx
The other option that you have is to add all the records in the selected items collection of the grid.
Something like:
xamDataGrid1.SelectedItems.Records.AddRange(xamDataGrid1.Records.ToArray());
Please let me know if you have any questions on this.
Regards,
Alex.
This doesn't work when the grid has Grouped fields.
The only records in the grid.Records collection are GroupByRecords, so it is a little more than filtering them out. I did manage to use that queue to take this code:
FieldSortDescription[] sorts = new FieldSortDescription[grid.FieldLayouts[0].SortedFields.Count]; grid.FieldLayouts[0].SortedFields.CopyTo(sorts, 0); grid.FieldLayouts[0].SortedFields.Clear(); grid.SelectedItems.Records.AddRange(grid.Records.ToArray()); foreach (FieldSortDescription sort in sorts) { grid.FieldLayouts[0].SortedFields.Add(sort); }And turn it into this code:if (grid.Records is GroupByRecordCollection) { foreach (GroupByRecord groupRecord in grid.Records) { grid.SelectedItems.Records.AddRange(groupRecord.ChildRecords.ToArray()); } } else { grid.SelectedItems.Records.AddRange(grid.Records.ToArray()); }Which has the added advantage of not collapsing the group if it happened to be open. Of course, more work would be needed to handle Summaries, etc if those were available on my grid.
You must filter out the GroupByRecord records before assigning them to the SelectedItems.
Thanks