Visible Records - I am attempting to obtain a collection of visible records (those visible under an expanded grouping), but much to my dismay the list of visible records returned is little more than a count of the groups and names of those groups in the nested view. Fairly useless. What I desire is to build a collection from the records seen when one expands a nested group.
My goal is to perform updates on just those records visible when a group is expanded.
What I have found as in other areas, grouping does not respect the total number of records in the currentview, but rather it maintains the parent source of n records. If one updates records under an expanded group, all records from the source are updated. Not desireable.
Naturally I expect the need to create the collection from the DataGrid Record, but less apparent is how to collect those records in the currently expanded view.
Glenn
private void DeselectedResourcesGrid_RecordsInViewChanged(object sender, RecordsInViewChangedEventArgs e) {
Petar,
Thanks for the tip. The GroupByRecord gave me a clue, but the final result was easier than tearing the GroupByRecord apart. See below. Hope this helps someone else. Seems like a common thing that should be better documented.
Glenn Long,
Valley Forge, PA
private void DeselectedResourcesGrid_RecordExpanded(object sender, RecordExpandedEventArgs
e)
{
// Some event name. save it for your birthday or something
eventName = e.RoutedEvent.Name.ToString();
// this only shows grouped by record names - pretty damn useless, yeah it's enumerable and you
// can loop through the viewable records, but whoopie - who cares
.DeselectedResourcesGrid.ViewableRecords;
// ok, here we get both group names and the actual records. now we got som'n.
);
// ok, now we got some kind of Infragistics handle - lets get a list of data items from it.
// this actually does jack, i just like using linq. for educational purposes.
{c.DataPresenter.DataItems}.DataItems.ToList());
// But wait, temp / results only contain the object handles, not the child data. we need to get the actual child records
// out of the GroupByRecord items shoved in the temp container
// Since temp returns all of the Groups we only want stuff from the currently expanded group.
// this is represented by the event and what's passed by e.record
;
// there are always two ways to skin the cat.
// stuff will contain our child collection, but they make you dig for it. not good for us lazy folk
// below is an option to pull the child records from the current group right out of the expanded record.
// do you have any kids?
// kool, this gives me all of the child records under my expanded list - wow!
myChildRecords = e.Record.ViewableChildRecords.ToList();
// ok, what do we do with this now? oh sure, just convert it back into the type we were using before the type
// was taken over by the grid record type. ok, forget about casting, that won't work. we need to do it manually
// watch this magic. Infragistics forgot to enter this in the manual
// Create a collection of my type
ASEngine.BusinessObjects.Entities.ResourceDeselects myManyCollection = new ASEngine.BusinessObjects.Entities.ResourceDeselects();
foreach (Infragistics.Windows.DataPresenter.Record rec in myChildRecords)
//this is just to verify i am not seeing things
// Add my converted type to my list
myManyCollection.Add((ASEngine.BusinessObjects.Entities.
ResourceDeselect)((Infragistics.Windows.DataPresenter.DataRecord
)(rec)).DataItem);
// ok, pass the plural of my object back to the main class and store in a variable so we can use to update with the column selector checkboxes.
// this will be overwritten each time a group is expanded.
// We do this because infragistics does not limit updates to only those records in view, by default all records are updated.
// Just think - this happens every time a group is expanded! We need to refresh the parent group just in case someone decides to update
// all of the records under this expanded group
}
Thanks, that helps but ...
GetRecordsInView(
true); provides you with a list of the groups/GroupByRecords and what looks like the first record in each group. What I need are the actual child records under the expanded item.
It looks like I need to get what I see in the GroupByRecord section of the GetRecordsInView(true) returned item. Do you know how to pull the child records out of the GroupByRecord? When I debug and look at the child record description, I see the number, but only parent records. I always find the list of ParentSource records beneath, but the ChildRecords element is always zero.
Thanks,
Hello Glenn,
If you want to get the records when a group is expanded I suggest using the RecordExpanded event like so:
private void xamDataGrid1_RecordExpanded(object sender, Infragistics.Windows.DataPresenter.Events.RecordExpandedEventArgs e) { var temp = e.Record.DataPresenter.GetRecordsInView(true); }
After which temp will contain an array of only the GroupByRecords and the expanded records as DataRecord.
Hope this helps.
Regards Petar.