>>I have a list that contains objects of a given class type which contains just a few properties. Two of these properties are:
>>string property called "Code"
>>string property called "HOCReason"
>>
>>This list can contain any number of items from 0 to n most likely not more than 10 or 12 records. I need to show them in a parent / child manner where I group all the records with the same Code together as the parent, and then show the children as only the HOC Reasons for those Code types. I am programmatically adding these values to a treeview control. Is there a linq way to obtain these from my List?
>>Timothy
>>
>>Svc_Code: 8FL Description: blah blah blah
>> HOC Reason: Whatever the reason is for this one
>> HOC Reason: Whatever this other reason may be
>>Svc_Code: 6SD Description: Some other description for this
>> HOC Reason: Some description for this item
>
>Check the third example:
http://msdn.microsoft.com/en-us/vcsharp/aa336754.aspx#nested>
>Looks like it does what you need to do.
I am not sure why I am struggling with this. I can get this done with some brute force method, but I know there is a simple way and I am just not seeing it. Since I do not have great Linq knowledge as of yet, I only suspect that Linq to Objects would do this.
I have received a collection of items and the contained items have way more properties than I need plus I need this data in a parent child relationship for binding to a treeview.
I now have an ObservableCollection of type DBHeavyObject
Contains properties for:
Code (string)
Description (string)
HOCReason (string)
.. Tons of other properties I don't need...
What I need is:
Collection of type DBLightParent - Only from the original DBHeavyObject where Code is unique
Contains three properties
Code (string)
Description (string)
Quantity(int) - this is the count of how many objects where in original collection of the same Code
And, another new collection of type DBLightChild - every object from original collection
Contains only two properties
Code (string)
HOCReason (string)
Can you help point me to a good example of how to do this without using brute force foreach loops?
Thanks
Timothy Bryan