This is a migrated thread and some comments may be shown as answers.

Find grid rows that are not filtered

8 Answers 157 Views
GridView
This is a migrated thread and some comments may be shown as answers.
MikeB
Top achievements
Rank 1
MikeB asked on 11 Feb 2009, 06:09 PM
Hi,
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

Sort by
0
Deyan
Telerik team
answered on 13 Feb 2009, 03:00 PM
Hi MikeB,

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.
0
Randw
Top achievements
Rank 1
answered on 26 Mar 2009, 11:37 PM
Um, I'm not finding rows that are filtered out.  All the collections in the grid that I inspect only show the unfiltered rows (Q2'08).  I'm trying to determine a record is displayed or not.  I could do it by index compared to the DataSource or search a column in the rows for a unique data value.  Anybody have code for that? 
Thanks,
- Rand
0
Deyan
Telerik team
answered on 30 Mar 2009, 04:37 PM
Hello 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.
0
Randw
Top achievements
Rank 1
answered on 30 Mar 2009, 06:04 PM
Thanks Deyan,

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
0
Deyan
Telerik team
answered on 31 Mar 2009, 09:01 AM
Hi 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.
0
Pioter
Top achievements
Rank 1
answered on 24 Feb 2021, 09:44 PM

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

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 25 Feb 2021, 01:41 PM

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/.

0
Pioter
Top achievements
Rank 1
answered on 25 Feb 2021, 02:23 PM

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!

 

Tags
GridView
Asked by
MikeB
Top achievements
Rank 1
Answers by
Deyan
Telerik team
Randw
Top achievements
Rank 1
Pioter
Top achievements
Rank 1
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or