Skip to content

Latest commit

 

History

History
47 lines (32 loc) · 1.59 KB

datagrid-maui-row-column-counts.md

File metadata and controls

47 lines (32 loc) · 1.59 KB
title description type page_title slug tags res_type
Retrieving Row and Column Counts in DataGrid for MAUI
Learn how to obtain the number of rows and columns in a DataGrid for MAUI.
how-to
How to Get Row and Column Counts in MAUI DataGrid
datagrid-maui-row-column-counts
datagrid, maui, rows, columns, count
kb

Environment

Version Product Author
10.0.0 DataGrid for .NET MAUI Dobrinka Yordanova

Description

I need to determine the number of rows and columns in a DataGrid.

This knowledge base article also answers the following questions:

  • How can I find out how many rows are in my DataGrid?
  • What is the method to know the number of columns in DataGrid?
  • Can I programmatically retrieve row and column counts in DataGrid?

Solution

To retrieve the number of rows and columns in a DataGrid for MAUI, follow the steps below:

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:

var rowNumber = (this.dataGrid.ItemsSource as ObservableCollection<FilesData>).Count.ToString();

2. Obtain the number of columns. The DataGrid exposes a Columns collection. Access this collection to get the amount of columns:

var columnNumber = this.dataGrid.Columns.Count.ToString();

These snippets give the total number of rows and columns in the DataGrid.

See Also

  • [DataGrid for MAUI Overview]({%slug datagrid-overview%})