Iterate over DataGrid rows using DataTable as ItemSource

1 Answer 71 Views
DataGrid
Clint
Top achievements
Rank 1
Iron
Iron
Clint asked on 10 Oct 2023, 12:19 AM

I've setup my DataGrid to have a checkbox column. I want to implement a feature where I can click the checkbox on one row, then left shift + click on a checkbox in another row and check it along with all the rows in between.

I can get the first row and detect the left shift + click to get the last row. My problem is that I can't see a way to iterate through the grid to capture all ids for the rows in between so I can check the boxes for those rows as well. 

Using DataGrid.ItemSource won't work because it won't respect any sorting, filtering, or grouping in the grid. How do I iterate through grid rows to find my first and last id and collect all ids in between?

1 Answer, 1 is accepted

Sort by
0
Accepted
Yana
Telerik team
answered on 12 Oct 2023, 02:26 PM

Hi Clint,

In this case you can use the DataGrid GetDataView() method which returns the data shown after all the Sort, Group and Filter  operations are applied.  GetDataView method returns an object of type IDataViewCollection which provides a read-only collection through its Items property with the already computed data from the ItemsSource.

Here is a quick example:

var dataGridData = this.grid.GetDataView().Items;

I hope this would be of help. Let me know if I can assist with anything else.

Regards,
Yana
Progress Telerik

A brand new .NET MAUI course was just added to the Virtual Classroom. The training course is developed to help you get started with the Telerik UI for .NET MAUI components and features. It aims to put you in the shoes of an engineer who adds new features to an existing application. You can check it out at https://learn.telerik.com
Clint
Top achievements
Rank 1
Iron
Iron
commented on 16 Oct 2023, 06:27 PM

Yes, this works perfect. Thanks!
Tags
DataGrid
Asked by
Clint
Top achievements
Rank 1
Iron
Iron
Answers by
Yana
Telerik team
Share this question
or