I have a need to create a list of items from a grid using only the rows that are displayed (not filtered). I tried to use the RowInfo.IsVisible property but it seems that all rows "IsVisible" is set to true even if the row is not visible due to it being filtered out.
The scenario is; The user creates a filter on a gird and then clicks a button (or whatever to trigger an event) and then the program needs to be able to get values from just the un-filtered rows.
Does anyone know how this can be done?
Thanks,
Mike B.
Update:
After more testing, the IsVisible does seem to be set to false for rows that are filtered out.
Sorry for "jumping the gun".
Mike B
8 Answers, 1 is accepted
I am glad that you have found a solution for your case but I think there is a better approach to do this so I decided to drop a line.
Each template in RadGridView has a Rows collection which contains the rows as they appear on the grid. Therefore, after you have filtered according to your preferences the rows that are displayed can be found in the Rows property of the corresponding template. I hope this is useful.
Do not hesitate to write me back if you have more questions.
Regards,
Deyan
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Thanks,
- Rand
You can consider the following code:
bool isContained = false; |
for (int i = 0; i < this.nwindDataSet.Customers.Rows.Count; i++) |
{ |
DataRow currentRow = this.nwindDataSet.Customers.Rows[i]; |
for (int k = 0; k < this.radGridView1.Rows.Count; k++) |
{ |
DataRowView visibleRow = this.radGridView1.Rows[k].DataBoundItem as DataRowView; |
if (currentRow[0].ToString() == visibleRow[0].ToString()) |
{ |
isContained = true; |
} |
} |
if (!isContained) |
{ |
Console.WriteLine(currentRow[0].ToString()); |
} |
isContained = false; |
} |
Basically, what I am doing is iterating over all rows that are contained in my data source I used to bind RadGridView. For each row from the data source I check whether a row with the same ID is contained in the Rows collection of the RadGridView (the visible rows). If not, I print the ID in the Console.
I hope this will help.
Sincerely yours,
Deyan
the Telerik team
Check out Telerik Trainer , the state of the art learning tool for Telerik products.
I'll use that code. Hey, such iteration of every row in a DataSet for every row in the grid is hugely inefficient and, well, not pretty. It would seem such a basic function that Telerik should consider a built-in method to determine whether databound rows are shown or filtered. IN my case I just want to get the next unfiltered row. An array of bools or something would greatly improve this functionality.
Thanks,
- Rand
Thanks for your question.
Currently we do not support this functionality out of the box since it has not been requested and we think that the custom approach could be effective in most of the cases.
Do not hesitate to write back in case of further questions.
Greetings,
Deyan
the Telerik team
Check out Telerik Trainer , the state of the art learning tool for Telerik products.
Hi, I know this is an old thread, but the original question described exactly the issue I am seeing - namely, my grid has filter engaged but every row appears as IsVisible==true even though it is filtered out. I checked and my FilterDescriptors is correct.
To illustrate, here is the content of my Immediate Window when there are no filters engaged - FiterDescriptors is empty and both Rows and Visible Rows are 423:
pfolioGrid.FilterDescriptors
Count = 0
pfolioGrid.Rows.Count
423
pfolioGrid.Rows.Where(x=>x.IsVisible).Count()
423
Now I am engaging the filter on one of the columns, my FilterDescriptors is reflecting this but still the visible Rows is 423:
pfolioGrid.FilterDescriptors
Count = 1
[0]: {[analytics_model_class] = 'ABS Triple Net Lease'}
pfolioGrid.Rows.Count
423
pfolioGrid.Rows.Where(x=>x.IsVisible).Count()
423
I really wonder what I am missing. Thanks in advance for any help
Hi, Pioter,
I would like to note that RadGridView exposes two collections that contain data rows:
Rows - contains all data rows that belong to RadGridView. Data operations such as grouping, sorting, filtering, etc. do not change the content of the collection or the order in which the row objects exist in the collection.
ChildRows - returns the data rows that are currently represented by RadGridView in the order in which they appear. The collection is modified every time a data operation (grouping, sorting, filtering) occurs.
The following help article demonstrates a sample example: https://docs.telerik.com/devtools/winforms/controls/gridview/rows/rows-vs-childrows
I believe that the ChildRows collection would be suitable for your case if you want to extract the filtered rows.
I hope this information helps.
Regards,
Dess | Tech Support Engineer, Sr.
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/.
Dess, this is great, thank you! I guess things changed since the original question was asked!
I also discovered an alternative solution to my issue that seems to be working - row.Index shows as >=0 only for not filtered rows and ==-1 for the filtered ones.
But I will switch to your solution! Thanks again!