Data from a Grouped, Filtered GridView

12 posts, 0 answers
  1. Jeanne
    Jeanne avatar
    13 posts
    Member since:
    Mar 2009

    Posted 03 Jun 2009 Link to this post

    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







  2. Stefan Dobrev
    Admin
    Stefan Dobrev avatar
    790 posts

    Posted 04 Jun 2009 Link to this post

    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.
  3. DevCraft banner
  4. Jeanne
    Jeanne avatar
    13 posts
    Member since:
    Mar 2009

    Posted 04 Jun 2009 Link to this post

    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
  5. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 05 Jun 2009 Link to this post

    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.
  6. Jeanne
    Jeanne avatar
    13 posts
    Member since:
    Mar 2009

    Posted 05 Jun 2009 Link to this post

    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


  7. Pavel Pavlov
    Admin
    Pavel Pavlov avatar
    2039 posts

    Posted 11 Jun 2009 Link to this post

    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.
  8. Paul Bradford
    Paul Bradford avatar
    5 posts
    Member since:
    Mar 2010

    Posted 01 Apr 2010 Link to this post

    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?
  9. Milan
    Admin
    Milan avatar
    1989 posts

    Posted 02 Apr 2010 Link to this post

    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.
  10. Paul Bradford
    Paul Bradford avatar
    5 posts
    Member since:
    Mar 2010

    Posted 02 Apr 2010 Link to this post

    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?
  11. Milan
    Admin
    Milan avatar
    1989 posts

    Posted 07 Apr 2010 Link to this post

    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.
  12. Paul Bradford
    Paul Bradford avatar
    5 posts
    Member since:
    Mar 2010

    Posted 15 Apr 2010 Link to this post

    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
  13. Milan
    Admin
    Milan avatar
    1989 posts

    Posted 21 Apr 2010 Link to this post

    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.
Back to Top
DevCraft banner