views:

1101

answers:

5

I have created a class for a dashboard item which will hold information such as placement on the dashboard, description, etc. I am currently using a pair of Collections to hold those dashboard items contained in the "library" and those items showing on the dashboard itself. I have been asked to make this dashboard multi-tab, and my first inclination was to make a new Collection for each tab. For this I would want some type of array or collection which could have many of these dashboard item collections added to it as more tabs are added to the dashboard.

Is this possible, and if so, could I get a little code snip for the declaration of such a collection? I have considered using a single collection with a variable to show which tab the item will be shown in... However, the display and routines to manage dashboard item movement between screen and library currently need those individual collections.

Edit: Thank you for your answers. While I do find them all interesting I believe I am going to go with James solution and will be marking it as the accepted answer.

+1  A: 

Why not create a class that contains your second collection and any of the previous information, and just have a collection of these items?

Charles Graham
I agree. At some point you're probably going to need more informaction for each "tab" rather than what objects are on it.
Kibbee
+6  A: 
List< List<Placement>> ListofListOfPlacements = new List< List<Placement>> ();

List<Placement> dashboard1 = new List<Placement>();
List<Placement> dashboard2 = new List<Placement>();
List<Placement> dashboard3 = new List<Placement>();
List<Placement> dashboard4 = new List<Placement>();

ListofListOfPlacements.Add(dashboard1);
ListofListOfPlacements.Add(dashboard2);
ListofListOfPlacements.Add(dashboard3);
ListofListOfPlacements.Add(dashboard4);
James Curran
A: 

why not put your collection of dash board items in a tabpage class?

like so:

public class DashboardTabPage : TabPage
{
    public List<DashboardItem> DashboardItems { get; set; }

    public DashboardTabPage() : this (new List<DashboardItem>())
    {

    }

    public DashboardTabPage(List<DashboardItem> items) :base ("Dashboard Thing")
    {
        DashboardItems = items;
    }

}

public class DashboardItem { }

then you can do this:

c.TabPages.Add(new DashboardTabPage());
Hath
A: 

Since you are talking about tabs, it sounds to me like you want something closer to a dictionary keyed on the tab name, with a set of items per tab. .NET 3.5 added the ILookup<,> interface:

        ILookup<string, Foo> items = null; //TODO
        foreach (Foo foo in items["SomeTab"])
        {
            Console.WriteLine(foo.Bar);
        }

Note that the MS implementation is immutable - you can't edit it after creation; however, I wrote an EditableLookup<,> in MiscUtil that allows you to work more effectively (just like a regular .NET collection):

        var items = new EditableLookup<string, Foo>();
        items.Add("SomeTab", new Foo { Bar = "abc" });
        items.Add("AnotherTab", new Foo { Bar = "def" });
        items.Add("SomeTab", new Foo { Bar = "ghi" });
        foreach (Foo foo in items["SomeTab"])
        { // prints "abc" and "ghi"
            Console.WriteLine(foo.Bar);
        }

Without EditableLookup<,>, you need to build the lookup via the Enumerable.ToLookup extension method.

If any part of this sounds like an option, I can add more detail...

Marc Gravell
A: 

I think you should go with composition, as below

Per user Dashboard-home(having multiple tabs) object containing list of dashboard objects containing list of dashboard item objects having various operations on them defined. Again the dashboard item can be a usercontrol having all possible events defined which are handled either there in dashboard item object and/or left to do for dashboard UI object that'll work with individual dashboard objects.

I guess this would be better manageable, if you are going to follow SOA and reusable component based architecture.

Kunal S