Back to Devexpress

CellRange.ColumnCount Property

officefileapi-devexpress-dot-spreadsheet-dot-cellrange-8c412b38.md

latest6.3 KB
Original Source

CellRange.ColumnCount Property

Gets the number of columns in the cell range.

Namespace : DevExpress.Spreadsheet

Assembly : DevExpress.Spreadsheet.v25.2.Core.dll

NuGet Package : DevExpress.Spreadsheet.Core

Declaration

csharp
int ColumnCount { get; }
vb
ReadOnly Property ColumnCount As Integer

Property Value

TypeDescription
Int32

An integer that specifies the number of columns.

|

Remarks

To obtain the number of rows in the cell range, use the CellRange.RowCount property.

If the current cell range is a complex (union) range, the ColumnCount property returns the number of columns in the rectangular cell range that covers all areas of the union range. For example, the ColumnCount value for the union range B3:C4, D6:E7 shown in the image below is 4.

The following code snippets (auto-collected from DevExpress Examples) contain references to the ColumnCount property.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

how-to-export-cell-range-to-a-datatable/CS/ExportToDataTableExample/Form1.cs#L40

csharp
if (firstDataRowIndex < rowCount) {
    for (int col = 0; col < range.ColumnCount; col++) {
        CellValueType cellType = range[firstDataRowIndex, col].Value.Type;

how-to-use-excel-add-ins-in-winforms-spreadsheet/CS/SpreadsheetAddIn/Form1.cs#L165

csharp
int height = parameter.RowCount;
int width = parameter.ColumnCount;
object[,] result = (object[,])Array.CreateInstance(typeof(object), new[] { height, width }, new[] { 1, 1 });

winforms-spreadsheetcontrol-api-part1/CS/SpreadsheetControl/SpreadsheetActions/CellActions.cs#L205

csharp
// Get the number of cells in the range.
int cellCount = sourceRange.RowCount * sourceRange.ColumnCount;

wpf-spreadsheetcontrol-api-part-1/CS/SpreadsheetControl_WPF_API/SpreadsheetActions/CellActions.cs#L158

csharp
// Get the number of cells in the range.
int cellCount = sourceRange.RowCount * sourceRange.ColumnCount;

how-to-export-cell-range-to-a-datatable/VB/ExportToDataTableExample/Form1.vb#L39

vb
If firstDataRowIndex < rowCount Then
    For col As Integer = 0 To range.ColumnCount - 1
        Dim cellType As CellValueType = range(firstDataRowIndex, col).Value.Type

how-to-use-excel-add-ins-in-winforms-spreadsheet/VB/SpreadsheetAddIn/Form1.vb#L178

vb
Dim height As Integer = parameter.RowCount
Dim width As Integer = parameter.ColumnCount
Dim result(,) As Object = CType(Array.CreateInstance(GetType(Object), {height, width}, {1, 1}), Object(,))

winforms-spreadsheetcontrol-api-part1/VB/SpreadsheetControl/SpreadsheetActions/CellActions.vb#L191

vb
' Get the number of cells in the range.
Dim cellCount As Integer = sourceRange.RowCount * sourceRange.ColumnCount

wpf-spreadsheetcontrol-api-part-1/VB/SpreadsheetControl_WPF_API/SpreadsheetActions/CellActions.vb#L147

vb
' Get the number of cells in the range.
Dim cellCount As Integer = sourceRange.RowCount * sourceRange.ColumnCount

See Also

RowCount

TopRowIndex

BottomRowIndex

LeftColumnIndex

RightColumnIndex

Union(CellRange)

Union

How to: Access a Range of Cells

CellRange Interface

CellRange Members

DevExpress.Spreadsheet Namespace