windowsforms-devexpress-dot-xtrapivotgrid-dot-pivotgridcontrol-0eb92f74.md
Gets the object which contains information on the cells that are displayed by the control.
Namespace : DevExpress.XtraPivotGrid
Assembly : DevExpress.XtraPivotGrid.v25.2.dll
NuGet Package : DevExpress.Win.PivotGrid
[Browsable(false)]
public PivotGridCells Cells { get; }
<Browsable(False)>
Public ReadOnly Property Cells As PivotGridCells
| Type | Description |
|---|---|
| PivotGridCells |
A PivotGridCells object which contains information on the data cells.
|
This property allows you to get view information on the cells displayed by the PivotGrid control (the number of columns, rows, the coordinates of the focused and selected cells).
The PivotGridCells.GetCellInfo method can be used to get information specific to particular cells. For instance, it’s possible to determine the type of a specific cell, the cell’s value and display text or get a list of the records which are associated with this cell.
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);
}
Imports DevExpress.XtraPivotGrid
Const CellDelimiter As String = vbTab
Const LineDelimiter As String = vbCrLf
Sub CopyToClipboard(ByVal PivotGrid As PivotGridControl)
Dim cells As PivotGridCells = PivotGrid.Cells
' Get the coordinates of the selected cells.
Dim cellSelection As Rectangle = cells.Selection
Dim result As String = ""
' Get the index of the bottommost selected row.
Dim maxRow As Integer = cellSelection.Y + cellSelection.Height - 1
' Get the index of the rightmost selected column.
Dim maxColumn As Integer = cellSelection.X + cellSelection.Width - 1
' Iterate through the selected cells.
Dim rowIndex, colIndex As Integer
For rowIndex = cellSelection.Y To maxRow
For colIndex = cellSelection.X To maxColumn
' Get the current cell's display text.
result += cells.GetCellInfo(colIndex, rowIndex).DisplayText
If (colIndex < maxColumn) Then result += CellDelimiter
Next
If (rowIndex < maxRow) Then result += LineDelimiter
Next
' Copy the resulting text to the clipboard.
Clipboard.SetDataObject(result)
End Sub
See Also