0

What I'm trying to do is to create a report using a datasource that also contains a child list.

So, an simple example is as follows, where a List of Items is my datasource and I want to also display the list of tasks.

public class Item
{
  public string itemName;
  public List<Task> tasks;
}

public class Task
{
   public string taskName;
}

The problem is that when I add the datasource, itemName shows up as a field but I can't see the tasks.

I found this question: How to display a child List inside of the DataSource in VS Report Viewer 2008? which seems similar, but I couldn't understand the answer. I'm pretty new at these reports so any help would be appreciated.

Thanks, Matt

Community
  • 1
  • 1
Matt
  • 322
  • 6
  • 12

1 Answers1

0

Not sure if that is what you want, but you might consider flattening your Item class into an array or list of strings and bind those to your target control. You can use the following LINQ code to get a flattened list of strings:

var tasks = from i in Items
            from t in i.Tasks
            select String.Format("{0}: {1}", i.ItemName, t.TaskName);

P.S.: It is usual not to use camel casing, but rather Pascal casing for public variables.

Alexander Galkin
  • 12,086
  • 12
  • 63
  • 115
  • That would certainly work, but its not quite what I want. I would like to have the item name at the top of my report followed by a list of items. I'd rather not repeat itemName over and over. – Matt Sep 08 '11 at 18:31