Solved

List Question

Posted on 2013-06-25
6
208 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

910 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now