How to get the last data row index

I am migrating a UWP application to WinUI and I need to convert the existing code for a UWP SfDataGrid to the equivalent syntax for the WinUI  SfDataGrid.

My current implementation includes a call to get the index of the last data row, so that it can be scrolled into view:

myGrid .ScrollInView(new RowColumnIndex(myGrid.GetLastDataRowIndex(), 0));

Unfortunately, I don't see any GetLastDataRowIndex()  method on the WinUI grid.

Can you please tell me how to achieve this? Thanks.


3 Replies 1 reply marked as answer

SS Sampathnarayanan Sankaralingam Syncfusion Team March 3, 2022 07:08 PM UTC

Hi Tim Coulter,


We are regret to inform you that the DataGrid.GetLastDataRowIndex() is not available in the WinUi platform. However you can get the index of last data row using the below code snippet.


public int GetLastDataRowIndex(SfDataGrid DataGrid)

{

    if (DataGrid.View.Records.Count == 0)

        return -1;

    int count = 0;

 

    VisualContainer visualContainer = (VisualContainer)DataGrid.GetType().GetProperty("VisualContainer", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).GetValue(DataGrid);

 

    int index = visualContainer.RowCount - (DataGrid.GetTableSummaryCount(TableSummaryRowPosition.Bottom) + 1);

    if (DataGrid.AddNewRowPosition == AddNewRowPosition.Bottom)

        index -= 1;

    if (DataGrid.FilterRowPosition == FilterRowPosition.Bottom)

        index -= 1;

    for (int start = index; start >= 0; start--)

    {

        if (!visualContainer.RowHeights.GetHidden(start, out count))

            return start;

    }

 

    return index;

}


Sample link : https://www.syncfusion.com/downloads/support/forum/173323/ze/Sample_DataGrid-286441284


Please have a look at the sample from the provided link and let us know if you have any concerns in this.


Regards,

Sampath Narayanan.S


Marked as answer

TC Tim Coulter March 3, 2022 08:48 PM UTC

Thank you very much Sampath.


That's a great solution.


Regards,

Tim



SS Sampathnarayanan Sankaralingam Syncfusion Team March 4, 2022 06:57 AM UTC

  
Hi Tim Coulter, 
 
We are glad to know that the reported problem has been resolved at your end. Please let us know if you have any further queries on this. We are happy to help you😊 
 
Regards, 
Sampath Narayanan.S 


Loader.
Up arrow icon