?
Solved

List Question

Posted on 2013-06-25
6
Medium Priority
?
215 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 2000 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

Command Line Tips and Tricks

The command line is a powerful tool at the disposal of every Linux user. Although Linux distros come with beautiful user interfaces, it's worthwhile to learn the command line because it allows you to do a number of things that you otherwise cannot do from the GUI.  

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

765 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