We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Get Rows count - best practice

Hi

sfdatagrid Rows collection doesn't exist.

The following code give me the number of rows. Is it the best practice to get the number of rows ?


public partial class OrderInfoRepositoryView : ContentPage
{
public OrderInfoRepositoryView()
{
InitializeComponent();
//BindingContext = vm.OrderInfoCollection;
        SfDataGrid dataGrid = new();

        OrderInfoRepositoryViewModel viewModel = new();
        dataGrid.ItemsSource = viewModel.OrderInfoCollection;
    }


    private void GetNumberofRows_Clicked(object sender, EventArgs e)
    {

        var nbOfRows = viewModel.OrderInfoCollection.Count;
        DisplayAlert("Number of Rows", $"the number of rows is {nbOfRows}.", "ok");
    }
}

3 Replies 1 reply marked as answer

NY Nirmalkumar Yuvaraj Syncfusion Team December 30, 2022 08:38 AM UTC

Hi,

You can use the Count property of the underlying collection, viewModel.OrderInfoCollection, to determine the number of items in the collection. However, this count will not update when you apply filters to the DataGrid. If you want to include the filtered rows in your count, we recommend using the View.Records property of the DataGrid. Here is an example of how to use it:

 

private void GetNumberofRows_Clicked(object sender, EventArgs e)

    {

        var nbOfRows = dataGrid.View.Records.Count;

        DisplayAlert("Number of Rows", $"the number of rows is {nbOfRows}.", "ok");

    }

Please let us know if we misunderstood your query.

 

Regards,

Nirmalkumar


Marked as answer

JE Jean-Marc December 30, 2022 12:55 PM UTC

Thank for the reply. It does clarify my needs.



KK Karthikraja Kalaimani Syncfusion Team January 3, 2023 09:45 AM UTC

We are glad that your requirement has been met on your side. Please let us know if you need further assistance. As always, we are happy to help you out. 


Loader.
Up arrow icon