Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
545
Mark all Cells with "Ctrl" + "A" & "Ctrl" + "C", Infragistics 14.1
posted

I have a small problem with copy xamPivotGrid data by using Ctrl + C.

To Copy all data from xamPivotgrid I'm using a KeyDown event on xamPivotGrid.

pivotGrid.KeyDown += (s, e) =>
{
    if (e.Key == Key.C && (ModifierKeys.Control == Keyboard.Modifiers))
    {
        if (pivotGrid.SelectionSettings.SelectedRows.Count > 0)
        {
            StringBuilder sb = new StringBuilder();
            sb.AppendLine("\t" + String.Join("\t", pivotGrid.SelectionSettings.SelectedRows.FirstOrDefault().Cells.Select(cell => cell.DataColumn.HeaderText)));
            foreach (var Item in pivotGrid.SelectionSettings.SelectedRows)
            {
                sb.AppendFormat("{0}\t", Item.HeaderText.Replace("\r\n", " "));
                sb.AppendFormat("{0}\n", String.Join("\t", Item.Cells.Select(a =>
                {
                    ICell Cell = (a.Data as ICell);
                    return Cell == null ? String.Empty : (a.Data as ICell).FormattedValue;
                })));
            }
            Clipboard.SetText(sb.ToString());
        }
    }
    if (e.Key == Key.A && ModifierKeys.Control == Keyboard.Modifiers)
    {
        foreach (Infragistics.Controls.Grids.PivotDataRow Row in pivotGrid.DataRows)
        {
            pivotGrid.SelectionSettings.SelectedRows.Add(Row);
        }
    }
};

The Problem is, I do not to Focus the Pivot Grid. If Pivot Grid is not focused, user cannot perform Mark + Copy. And the focus works only if I'm using TAB key. Usually a click on control element should be enough to set the focus. Is there any easy way to perform copy of table?

wbr

Roman

Parents
No Data
Reply
  • 17475
    Offline posted

    Hello Roman and thank you for posting!

    I have been looking into your requirements and created a sample project based on the provided code snippets for cell selection and copying. It seems that the solution selects and copies the displayed values of the grid correct when the control is focused. If the control is not focused, the key events will be handled by the control (xamPivotGrid) that has the focus and the select and copy operation will not be performed for XamPivotGrid.
    Could you please have a look at the sample application and let me know if it meets your requirements or the requirements you need to meet are different? Please feel free to modify the project to illustrate the scenario on your side.

    XamPivotGridCopy.zip
Children