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
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.
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
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.
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
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.
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.
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?
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.
paul
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.