tags:

views:

29

answers:

2

I have a collection of items that is populated from LINQ and I have the need to access a sibling item (a date), that will be set from the UI level. Since I do not know the date at the time the data collection is populated, I need a good way to access the date property from each of the items in the collection. Here is my class structure stripped down:

public class TestClass
{
    public DateTime MyDate;
    public List<MySite_ReportResult> Items { get; set; }
}

To summarize, for each "MySite_ReportResult", I want to be able to access "MyDate". Does anyone have a good suggestion that is a best practice? This collection will eventually be bound to a grid, so I will be creating a partial class and adding an additional property based on what the DateTime value is.

+1  A: 

Could this help?

...

List<DatedReportResult> list = new List<DatedReportResult>();

foreach (var drs in list) {
   drs.ReportDateTime ..
}

...

class DatedReportResult {
   public DateTime ReportDateTime;

   /* Properties of original ReportResult class */
   ....
}

Conversely for the UI you could bind the list, use a BindingSource and access the current item's ReportDateTime property in your code.

Hope this helps.

Thanks

lb
+1  A: 
Micael Bergeron
I ended up having a lot of other complications with typing and the fact that this class was actually using generics (maybe I shouldn't have simplified it so much) and was used in many places, but your solution was helpful in getting toward my resolution so thank you very much.
rattrick1