Hi,
Does the XamPivotGrid support clipboard operations. I would like to select a row/column or hierarchie and copy paste all selected cells into Excel. The XamDataGrid can easily do this through Clipboard operations, is there a simple way of doing it with the XamPivotGrid?
Thanks,Nick
Hello Nick,
I have been looking into your question and I believe that you can achieve the functionality that you require with our XamPoivotGrid. In order to achieve this you can try to handle the usercontrol’s KeyDown event and there to save to clipboard all of the selected cells. For example you can copy to clipboard the whole selected row as follows:
private void pivotGrid_KeyDown(object sender, KeyEventArgs e)
{
StringBuilder clip= new StringBuilder();
if (e.Key == Key.C&&(ModifierKeys.Control==Keyboard.Modifiers))
foreach (PivotDataRow row in pivotGrid.SelectionSettings.SelectedRows)
foreach (PivotCell c in row.Cells)
clip.Append(c.Control.Content.ToString() + '\t');
Clipboard.SetText(clip.ToString());
}
If you need any further assistance on this matter, please do not hesitate to ask.
Hi Elena,
Thanks for the reply, however this appears to work only for the cells in my current view. If i have 10 cells and the first 5 of them are in view the values for those 5 are copied. If i scroll the next 5 into view then only they are copied even though i am selecting the whole row.
Basically c.Control is set to null for any cell that is not in view because of the grid virtualisation.
Regards,Nick
Would you try replacing the invoking of the cell control value with the following snippet:
clip.Append((c.Data as ICell).FormattedValue + '\t');
Please let me know if this still doesn’t suits your scenario.
Thanks for the answer, that works great. Why is it not possible to do the same for SelectionSettings.SelectedColumns? They don't seem to contain a PivotCellCollection.
You can perform similar implementation for the columns too. As you noticed the PivotDataColumn doesn’t contain collection for all of its cells, still you can access them through the Result property of the DataSource as follows:
foreach (PivotDataColumn col in pivotGrid.SelectionSettings.SelectedColumns)
int colIndex = pivotGrid.DataColumns.IndexOf(col);
for (int rowIndex=0;rowIndex<pivotGrid.DataRows.Count;rowIndex++ )
clip.Append(pivotGrid.DataSource.Result.Cells[rowIndex, colIndex].FormattedValue + '\n');
If you have any further questions or concerns on this matter, please let me know.