Skip to content

Commit 04c1d70

Browse files
author
KB Bot
committed
Added new kb article datagrid-maui-row-column-counts
1 parent ff10615 commit 04c1d70

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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
31+
32+
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:
33+
34+
```csharp
35+
var rowNumber = (this.dataGrid.ItemsSource as ObservableCollection<FilesData>).Count.ToString();
36+
```
37+
38+
**2.** Obtain the number of columns
39+
40+
The DataGrid exposes a `Columns` collection. Access this collection to get the amount of columns:
41+
42+
```csharp
43+
var columnNumber = this.dataGrid.Columns.Count.ToString();
44+
```
45+
46+
These snippets gives the total number of rows and columns in the DataGrid.
47+
48+
## See Also
49+
50+
- [DataGrid for MAUI Overview]({%slug datagrid-overview%})
51+

0 commit comments

Comments
 (0)