Solved

List Question

Posted on 2013-06-25
6
212 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
MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

 
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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…

829 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