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

Data from a Grouped, Filtered GridView

11 Answers 178 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Jeanne
Top achievements
Rank 2
Jeanne asked on 03 Jun 2009, 10:44 PM
I need to be able to loop through the records of a grouped, filtered gridview.  If I do this:

Telerik.Windows.Data.RecordCollection rec = (Telerik.Windows.Data.RecordCollection)OperDataReport.Records;

I get this error:

Unable to cast object of type 'Telerik.Windows.Data.VirtualizingRecordCollection' to type 'Telerik.Windows.Data.RecordCollection'.

How do I get the VirtualizingRecordCollection cast to a RecordCollection or to anything I can use?  Are there any examples available?

Thanks,
Jeanne







11 Answers, 1 is accepted

Sort by
0
Stefan Dobrev
Telerik team
answered on 04 Jun 2009, 01:26 PM
Hello Jeanne,

You can loop through the filtered records using standard foreach operator:
foreach (var record in this.GridView.Records) 
    ... 

Do you get some incorrect information when you do this?

Kind regards,
Stefan Dobrev
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
Jeanne
Top achievements
Rank 2
answered on 04 Jun 2009, 04:49 PM
I think you're missing the part about the grid being ~grouped~.  Yes, it is also filtered.  There is only 1 record in .Records even though the grid shows 7 records.  That one record is of type:

OperDataReport.Records = {Telerik.Windows.Data.VirtualizingRecordCollection}

The question at hand is how dig into that VirtualizingRecordCollection to get at the 7 data records that are displayed in the grid?

Please help!  I'm so close to having to pull out the Telerik grid.

Jeanne
0
Vlad
Telerik team
answered on 05 Jun 2009, 05:37 AM
Hello Jeanne,

Can you please provide more detailed info about your scenario and requirements -  we will gladly provide you running example project!

Greetings,
Vlad
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
Jeanne
Top achievements
Rank 2
answered on 05 Jun 2009, 07:47 PM
I can't upload code to the forum.  However, I if you grab one of the examples I've submitted for errors (say the Masked Edit example) and use it as an example, you can easily modify it to create this problem.

Step 1:  Put a gridview on a the first tab.  Include one column that is identical for every row.  Group on that column, thus allowing aggregate functions to be used to display counts and sums.  Here is my gridview:

                        <telerik:RadGridView x:Name="OperDataReport" AutoGenerateColumns="True" CanUserFreezeColumns="False"
                            CanUserReorderColumns="True" CanUserResizeColumns="True" IsReadOnly="True" MultipleSelect="True"
                            IsFilteringAllowed="True" ShowGroupPanel="False" ColumnsWidthMode="Auto" RowIndicatorVisibility="Collapsed">
                            <telerik:RadGridView.GroupDescriptions>
                                <tdata:RadGroupDescription PropertyName="ConstructionYear" SortDirection="Ascending">
                                    <tdata:RadGroupDescription.AggregateFunctions>
                                        <tdata:CountFunction FunctionName="Count" SourceField="ClearinghouseKey" Caption="Row Count:" />
                                        <tdata:SumFunction FunctionName="TotalUnits" SourceField="SumOfUnits" Caption="Total Units:" />
                                        <tdata:SumFunction FunctionName="TotalSqFt" SourceField="SumOfSqFt" Caption="Total SqFt:" />
                                        <tdata:SumFunction FunctionName="TotalAcreage" SourceField="SumOfAcreage" Caption="Total Acreage:" />
                                    </tdata:RadGroupDescription.AggregateFunctions>
                                </tdata:RadGroupDescription>
                            </telerik:RadGridView.GroupDescriptions>
                        </telerik:RadGridView>

Step 2:  Now filter and by a different column so that only 7 or 8 rows are showing.  The aggregates update to respect the filter - yeah!

Step 3:  Grab the SelectionChanged event for the tabs and check to make sure you are moving from the first tab to the second.  The second tab will contain a graph of the selected rows in the first tab. 

Step 4.  In the SelectionChanged event try to loop through the records of the gridview.  For the above I put a check in for the count of the records property:
                        if (OperDataReport.Records.Count == 1)
Sure enough --- it is always 1 record, and as I stated above it is of type:  Telerik.Windows.Data.VirtualizingRecordCollection

How do I get to the "RealRecords" (you can see that property if you hover over .Records) and iterate to get the data?

Jeanne


0
Pavel Pavlov
Telerik team
answered on 11 Jun 2009, 08:59 AM
Hi Jeanne,

I have prepared a small example resembling your scenario. Please have a look at the attached project.
There is a grouped RadGridView.  The iteration logic is placed in the click handler of the 'Iterate' button. 

To test it just filter by Age and press the Iterate button .

Let me know if you need any further assistance on adapting this approach to your scenario.

 
Best wishes,
Pavel Pavlov
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
Paul Bradford
Top achievements
Rank 1
answered on 01 Apr 2010, 05:36 PM
Is this 'Records' property still available?  We are running the latest version of the Silverlight controls suite (2010.1.309.1030), but cannot find a Records property.  We need the same information - the updated grid data collection with the applied grouping / sorting as chosen by the user.  Is there another way to access this data?
0
Milan
Telerik team
answered on 02 Apr 2010, 07:15 AM
Hello Paul Bradford,

The Records property was removed a long time ago but there is a new property now (called Items) that contains the data collection.


Kind regards,
Milan
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Paul Bradford
Top achievements
Rank 1
answered on 02 Apr 2010, 08:43 PM
Hello.  Thanks for the quick reply.

The Items collection doesn't fit our need exactly as it can result in a nest collection that contains Groups if any grouping has been applied to the grid.  What we would like is a pure collection of the data source objects without any groups. We have tried casting the Items collection to several collection interfaces (IList, ICollection, etc..) that the DataItemsCollection implements, but none will provide what we need.  Is there a property / method we can use to access just the data item objects?
0
Milan
Telerik team
answered on 07 Apr 2010, 04:25 PM
Hi Paul Bradford,

Could you please take a look at this forum post. There you will find a zip file (called ticketid-286445-getfiltereditemsfromgroupedgrid.zip) which contains a sample project demonstrating how you can get a flat Items collection in grouped scenarios.


All the best,
Milan
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Paul Bradford
Top achievements
Rank 1
answered on 15 Apr 2010, 06:42 PM
Thanks Milan.  That code works great, with one exception.  When we call the FlatItems extension method in the Grouped event of the grid, the Items collection has not yet been updated to reflect the most recent grouping change.  If we instead use the DataLoaded event of the grid, the Items collection has been updated to relect the most current state.  So it appears the Grouped event is being fired before results of the grouping have been completely applied to the properties of the grid (the IsGrouping property also appears to have this same issue).

paul
0
Milan
Telerik team
answered on 21 Apr 2010, 10:34 AM
Hi Paul Bradford,

The groups should indeed be available in the Grouped event but it seems that this is not the case. We have logged this issue and will fix it as soon as possible.

We have done some changes to our Items collection and in our future builds Items will return flat collection no matter if the grid is grouped or not - this will remove the need to use FlatItems extension. Items will also expose a property called Groups which will provide access to the groups.

For the time being you can use  Dispatcher to get the items after they have been updated:

01.void myGrid_Grouped(object sender, GridViewGroupedEventArgs e)
02.{
03.    this.Dispatcher.BeginInvoke(new Action(
04.  
05.        () =>
06.        {
07.            var flatItems = this.myGrid.Items.OfType<object>();
08.        }
09.  
10.        ));
11.}

Thank you for your feedback and cooperation. I have updated your Telerik points.


Regards,
Milan
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
GridView
Asked by
Jeanne
Top achievements
Rank 2
Answers by
Stefan Dobrev
Telerik team
Jeanne
Top achievements
Rank 2
Vlad
Telerik team
Pavel Pavlov
Telerik team
Paul Bradford
Top achievements
Rank 1
Milan
Telerik team
Share this question
or