PivotGridCells.Selection Property
Gets or sets the coordinates of the selected cells.
Namespace: DevExpress.XtraPivotGrid
Assembly: DevExpress.XtraPivotGrid.v24.2.dll
Declaration
Property Value
Type | Description |
---|---|
Rectangle | A Rectangle object which contains the coordinates of the selected cells. |
Remarks
The PivotGrid control allows its cells to be selected. The Left and Top members of the Selection property identify the column index and row index of the left-topmost selected cell. The Width and Height members specify the number of selected columns and rows respectively.
You can use the Selection property to modify the cell selection.
To get information on any cell (including the selected ones) use the PivotGridCells.GetCellInfo method.
Example
The following example demonstrates how to manually copy the display text of the control’s selected cells to the Clipboard. The selected cells are identified by the PivotGridCells.Selection
property.
You can also use the PivotGridCells.CopySelectionToClipboard method to copy the selected cells to the Clipboard.
using DevExpress.XtraPivotGrid;
const string CellDelimiter = "\t";
const string LineDelimiter = "\r\n";
void CopyToClipboard(Pivot Grid Control pivotGrid) {
PivotGridCells cells = pivotGrid.Cells;
// Get the coordinates of the selected cells.
Rectangle cellSelection = cells.Selection;
string result = "";
// Get the index of the bottommost selected row.
int maxRow = cellSelection.Y + cellSelection.Height - 1;
// Get the index of the rightmost selected column.
int maxColumn = cellSelection.X + cellSelection.Width - 1;
// Iterate through the selected cells.
for(int rowIndex = cellSelection.Y; rowIndex <= maxRow; rowIndex++) {
for(int colIndex = cellSelection.X; colIndex <= maxColumn; colIndex++) {
// Get the current cell's display text.
result += cells.GetCellInfo(colIndex, rowIndex).DisplayText;
if(colIndex < maxColumn) result += CellDelimiter;
}
if(rowIndex < maxRow) result += LineDelimiter;
}
// Copy the resulting text to the clipboard.
Clipboard.SetDataObject(result);
}