Skip to content

Commit e1a31b3

Browse files
Merge pull request #1113 from telerik/new-kb-datagrid-maui-row-column-counts-18f15cc60fbc451e9ad8604cf522d3d8
Added new kb article datagrid-maui-row-column-counts
2 parents 0a6f1b1 + df25391 commit e1a31b3

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
---
2+
title: Retrieving Row and Column Counts in DataGrid for MAUI
3+
description: Learn how to obtain the number of rows and columns in a DataGrid for MAUI.
4+
type: how-to
5+
page_title: How to Get Row and Column Counts in MAUI DataGrid
6+
slug: datagrid-maui-row-column-counts
7+
tags: datagrid, maui, rows, columns, count
8+
res_type: kb
9+
---
10+
11+
## Environment
12+
13+
| Version | Product | Author |
14+
| --- | --- | ---- |
15+
| 10.0.0 | DataGrid for .NET MAUI | [Dobrinka Yordanova](https://www.telerik.com/blogs/author/dobrinka-yordanova) |
16+
17+
## Description
18+
19+
I need to determine the number of rows and columns in a DataGrid.
20+
21+
This knowledge base article also answers the following questions:
22+
- How can I find out how many rows are in my DataGrid?
23+
- What is the method to know the number of columns in DataGrid?
24+
- Can I programmatically retrieve row and column counts in DataGrid?
25+
26+
## Solution
27+
28+
To retrieve the number of rows and columns in a DataGrid for MAUI, follow the steps below:
29+
30+
**1.** Obtain the number of rows. The DataGrid generates rows based on the count of items in the collection bound to the `ItemsSource` property. Use the following code to get the number of rows:
31+
32+
```csharp
33+
var rowNumber = (this.dataGrid.ItemsSource as ObservableCollection<FilesData>).Count.ToString();
34+
```
35+
36+
**2.** Obtain the number of columns. The DataGrid exposes a `Columns` collection. Access this collection to get the amount of columns:
37+
38+
```csharp
39+
var columnNumber = this.dataGrid.Columns.Count.ToString();
40+
```
41+
42+
These snippets give the total number of rows and columns in the DataGrid.
43+
44+
## See Also
45+
46+
- [DataGrid for MAUI Overview]({%slug datagrid-overview%})
47+

0 commit comments

Comments
 (0)