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

Iterating on Rows

9 Answers 1747 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Deepa
Top achievements
Rank 1
Deepa asked on 17 Jun 2009, 07:33 AM
Hi

I have a RadGridView in this I wants to iterate on rows but I cannot get radgridview1.Rows for this which library,namespaces used.how to slove this proble.how can i achive this proble.

9 Answers, 1 is accepted

Sort by
1
Milan
Telerik team
answered on 17 Jun 2009, 08:05 AM
Hello Deepa,

You can sue the following snippet:
var rows = this.GridView.ChildrenOfType<GridViewRow>(); 
This will get all rows of the grid. You just have to import the namespace Telerik.Windows.Controls so that you can have access to the ChildrenOfType extension method.

One thing to have in mind is that only the visible rows will be returned by that method. That is because RadGridView uses virtualization and only a subset ot all rows are created.

Hope this helps.

Regards,
Milan
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
Deepa
Top achievements
Rank 1
answered on 17 Jun 2009, 09:08 AM
Hi

Thanks for reply.
I used snippet in this  rows get all rows of gridview but i get extra one new row
please give an example how to iterate on gridview and read all rows cells.
0
Milan
Telerik team
answered on 17 Jun 2009, 09:39 AM
Hello Deepa,

The first one is the new row which you can skip. The GridViewRow class has property called Cells, which gives you access to all cells of a particular row. To iterate over all visible rows and cells you can do something like that:

var rows = this.gridView.ChildrenOfType<GridViewRow>();  
 
foreach (var row in rows)  
{  
    if (row is GridViewNewRow)  
        continue;  
 
    foreach (var cell in row.Cells)  
    {  
          
    }  
}  
 



Kind regards,
Milan
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
Deepa
Top achievements
Rank 1
answered on 17 Jun 2009, 11:23 AM

Hi

I wants to use radgridview1.rows.count.but i can not get this means radgridview1.rows not find for this which library require
how can i achive this problem.
0
Milan
Telerik team
answered on 18 Jun 2009, 05:38 AM
Hi Deepa,

I am not sure that understant your question. Could you elaborate on it?

Unfortunately RadGridView does not have a property called Rows.
If you want to get the number of the rows you can do that:

var rows = this.gridView.ChildrenOfType<GridViewRow>();  
row.Count 

Just remember that Count will return the number of rows that are visible - not all rows of the grid. If you want to the number of all elements in the grid you can use RadGridView.Records.Count.

Greetings,
Milan
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
Calvin
Top achievements
Rank 2
answered on 23 Oct 2011, 05:30 AM
Greetings,

This technique does not reliably enumerate all visible rows after expanding or collapsing groups and/or applying or removing filtering.

    /// <summary>
    /// Returns <see cref="PartTargetMarketsMap"/>s that are visible (i.e., aren't filtered) or hidden in collapsed groups
    /// </summary>
    private IEnumerable<PartTargetMarketsMap> AllVisibleDataItems() {
        Contract.Assume(_grid.EnableRowVirtualization == false);
        return _grid.ChildrenOfType<GridViewRow>().Select(_ => _.DataContext).OfType<PartTargetMarketsMap>();
    }


For example, after grouping, then collapsing and expanding one or more groups and/or applying filtering to various columns, the foregoing code usually does not correctly enumerate only the rows that are "visible".  That is, this code does not list only the rows that are not concealed within a collapsed group or filtered out.

Here's my scenario.  I have a CheckBox in the header cell of a GridViewCheckBoxColumn.  This header check box is provided so that users can set or unset all checkboxes in the column.  But the user is also able to filter and group the grid.  So when the user toggles the header checkbox, possibly after either filtering or grouping the grid, only the "visible" cells in that column should be set.  By visible, I mean all cells that are not filtered from sight or hidden in collapsed groups.  Also, since I'm not using RowVirtualization, if rows are visible but scrolled out of view, they should be included in the "visible" rows enumeration.  I've hooked up handlers to the Grouped, GroupRowIsExpandedChanged, and Filtered events to update the header cell's CheckBox.IsChecked state based on the boolean values of the rows that are visible as these events fire.

So the header checkbox has a dual purpose.  First, it is provided so the user can set and unset all visible checkboxes in the column.  And second, it reflects collective checked status as the grid is filtered and grouped, and as the user checks/unchecks various cells in the column.  For both purposes, I need a reliable way of determining the visible rows.

Any ideas how to achieve this end?

Many thanks! 
0
AdaDog
Top achievements
Rank 1
answered on 03 Jan 2012, 07:10 PM
Has there been resolution on this issue?  Getting the count of rows that meet the filter criteria seems like a reasonable feature.  Something like "N of N,NNN matches" to display somewhere in the UI.
0
Kalyan
Top achievements
Rank 1
answered on 04 Jul 2012, 06:57 AM
Hi,

 using childrenoftype, only visible rows in Gridview can only be accessed while iterating through Gridview but how to iterate through all the rows of RadGridview in wpf
0
Rocio
Top achievements
Rank 1
answered on 17 Sep 2012, 12:10 PM
If you want to iterate through all the rows, you can do it the same way but turning off the enableRowVirtualization.
Tags
GridView
Asked by
Deepa
Top achievements
Rank 1
Answers by
Milan
Telerik team
Deepa
Top achievements
Rank 1
Calvin
Top achievements
Rank 2
AdaDog
Top achievements
Rank 1
Kalyan
Top achievements
Rank 1
Rocio
Top achievements
Rank 1
Share this question
or