Solved

List Question

Posted on 2013-06-25
6
210 Views
Last Modified: 2013-06-25
I have a c# (.net 4.5) windows application. I want to build a list of menu settings (see items below) that I will loop through to build menus.

What is the best way to store this in 4.5? There are so many other ways to store lists now, but they all seem to be geared towards storing just an identifier & a value or they require some convoluted way to store additional data.

The items I need to store for each menu is:
•      MenuGroup
•      MenuName
•      DisplayOrder
•      MenuLink
•      MenuIcon
•      MenuForeColor
•      MenuBGColor
0
Comment
Question by:Lensolo
  • 2
  • 2
  • 2
6 Comments
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 39275481
Why not create a class that encompasses those items listed above? Then create a list of this new class?

e.g.

public class MenuDetails
{
	public string MenuGroup { get; set; }
	public string MenuName { get; set; }
	public int DisplayOrder { get; set; }
	public string MenuLink { get; set; }
	public Image MenuIcon { get; set; }
	public Color MenuForeColor { get; set; }
	public Color MenuBGColor { get; set; }
}

Open in new window


List<MenuDetails> menuList = new List<MenuDetails>();

Open in new window

0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 39275484
>>or they require some convoluted way to store additional data.

Create a class with the data you require.  Now create a generic List<xxx> of your classes.
0
 

Author Comment

by:Lensolo
ID: 39275544
I think this might work. How do I set the values? This doesn't work. I haven't messed with custom classes yet. I'm new to c#.

 List<MenuItems> MenuList = new List<MenuItems>();
 MenuList.Add("Group1", "Menu Item", 1, "Link", "Icon", "Forecolor", "Background");
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
ID: 39275569
You need to create new instances of the class; then add these instances to the list.

List<MenuItems> MenuList = new List<MenuItems>();
MenuItems item = new MenuItems()
{
    MenuGroup = "Group1",
    MenuName = "Menu Item",
    DisplayOrder = 1,
    MenuLink = "Link",
    MenuIcon = "Icon",
    MenuForeColor = "Forecolor",
    MenuBGColor = "Background",
};

 MenuList.Add(item);

Open in new window

0
 

Author Closing Comment

by:Lensolo
ID: 39275594
Thanks for taking the extra step. This was just what I was looking for.
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 39275619
Next - if you want sub menus as well as just plain menu items you can just expand the above.  Think about how - you actually have the answer.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question