Hello,
How can I select all expanded/visible rows in a radgridview control, which have been grouped and possibly filtered, even if the rows fall out of view of the window container?
I have a window that contains a radgridview and a button that is outside of the grid which selects or deselects all visible rows in the radgridview. An end user may add multiple groupings and filters. There is a lot of data in the item source, at the time of this test over 3 thousand rows. The resulting data display after the end user has made changes will likely exceed the window containers viewable area. when I implemented the line of code below only the expanded row visible in the window was selected. The expanded rows that I had to scroll down to see were not selected. I would like to select all of the expanded/visible rows.
var visibleRows = grdBatches.ChildrenOfType<GridViewRow>();
I have read that ChildrenOfType<T> works on visual elements. In another forum question, the answer stated that the use of visual elements is not advised when working with virtualized controls such as the radgridview.
1 Answer, 1 is accepted
Hello Shannon,
To select rows, I recommend you to use the selection API of RadGridView. For example, you can use the SelectedItems collection property of RadGridView or the Select method. You can use this API to select data items from the ItemsSource collection, instead of using the GridViewRow visual containers.
To get all items that are present in the current data view (after filtering), use the Items collection property of RadGridView.
So, to select all available rows after filtering, you can add all items from the Items collection to the SelectedItems collection.
Regards,
Martin Ivanov
Progress Telerik
Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.
Hello,
I'm going to restate my issue because the original description is not completely accurate. Let's disregard the row selection.
My actual issue is finding the visible/expanded rows even if they have fallen outside of the window container or as you stated, getting all items that are present in the current data view (after filtering).
The code below only works if I set the grid property EnableRowVirtualization to false. However, Telerik strongly advises not disabling virtualization on the radgridview visual element because it may cause performance and loading issues.
var visibleRows = grdBatches.ChildrenOfType<GridViewRow>();
What property or method would return all visible/expanded rows?
Thank you,
You can't get all GridViewRow controls when the UI virtualization is on. This is because in that case only the rows in the viewport are generated. When you scroll up or down, the same GridViewRow instances will be re-used. Only their data item is replaced and they are re-arranged according to the new viewport. In case the viewport size changes, new row visuals will be generated or removed.
In order to work with the rows in gridview, you should use data bindings for their properties or to the elements in their data templates (like the CellTemplate of the column). This way you can work with the data items of the ItemsSource or the Items collection.
To select all rows in the current data view, whether their GridViewRow visuals are rendered, you can call the SelectAll method of RadGridView. Or alternatively, you can manually add all items from the RadGridView's Items collection to the SelectedItems collection. But note that this will work only if the SelectionMode of RadGridView is set to Multiple or Extended.
If this information doesn't help, can you send over few pictures and some code snippets showing your setup and the desired result?
Thank you, Martin. Here is the code that I am working with. I didn't save any code from testing.
So, you don't mean to select the items as in the context of RadGridView selection feature, but instead to raise the IsActive flag of the data items. Please correct me if I am wrong.
I've attached a sample project based on your code, that shows how to get the desired effect. I hope that helps.
Correct, a user will apply filters and grouping to the radgridview.
However, for every row open on the page, even if it is outside of the viewable container, I need to check the is active checkbox.
Great to hear that the project was useful.
You can mark only answers as ...well, Answer. However, the communication until now is in the comment section of your original Question, so you cannot mark it as an Answer. I can convert my comment with the solution to an Answer, but this will remove it from the comments and the communication at the end may look a bit odd. Currently, lets leave it that way.
About getting a survey, keep in mind that this is the public forum where the main idea is for the community to be active, to help each other and to discuss ideas. The Telerik stuff is helping as much as possible, but we don't promise any answers in the forums. If you need a dedicated support, you can use the ticketing system in your telerik.com account. This way you can rate the communication there and leave feedback.
I found the answer in the Telerik article linked below. However, Telerik stongly advises against this solution. Can anyone help me come up with another solution?
I set the Radgridview EnableRowVirtualization property to false and now I am able to select all expanded/visible rows using the code below.
var visibleRows = grdBatches.ChildrenOfType<GridViewRow>();
However, the UI virtualization article in the link below strongly advises against disabling UI virtualization due to performance issues and increased loading time. It is highly not recommended.
https://docs.telerik.com/devtools/wpf/controls/radgridview/features/ui-virtualization?_ga=2.152316729.1623548671.1676991592-610389054.1563760323&_gl=1*7tv5a5*_ga*NjEwMzg5MDU0LjE1NjM3NjAzMjM.*_ga_9JSNBCSF54*MTY3NzE2NTE1MC4zNC4xLjE2NzcxNjc1NTkuNTguMC4w
Thank you,