well, i’m almost new to c# and i couldn’t figure out how multi-leveled-arrays work in c#.
i’ve made a treeView with menus in it like:
- menu_1
- –child_1.1
- –child_1.2
- —-child_1.2.1
- —-child_1.2.2
- —-child_1.2.3
- –child_1.3
- Menu_2
- –child_2.1
- –child_2.2
- —-child_2.2.1
every single MenuItem should have 6 proppertys / attributes / values like this :
Item = { ID:int , “NAME:String , POSITION:String , ACTIVE:Bool , ACTION:bool , PATH:string }
so :
Menu_1 = { 1, "File", "1", true, false, "" }
child_1.1 = { 2, "Open", "1.1", true, true, "./open.exe" }
… and so on
so far :
i’ve manually set some String-Arrays ( String[] ) for eath menuItem and filled it with the informations.
String[] Item_1 = {"1", "File", "1", "1", "0", ""};
String[] Item_2 = ...
...
now i want to put all those String-Array inside an ArrayList[] and Sort() them using the “POSITION” value of each Item ( Item_1[2] )
also i want the code to dynamicly create that Array of the Item itself, reading the values from a sql table. those arrays should NOT be just String-Arrays as i did for now, cuz i want the ID to stay a int & the ACTIVE and ACTION value to stay a bool.
the final product should look like this :
MenuItems = ArrayList(
item_1 = Array(Int, String, String, Bool, Bool, String) // \
item_2 = Array(Int, String, String, Bool, Bool, String) // \
item_3 = Array(Int, String, String, Bool, Bool, String) // / all sortet by the 3rd value, the position )
item_4 = Array(Int, String, String, Bool, Bool, String) // /
...
)
)
thanx all of you who can help me out.
Assuming you’re on C# 2.0 or later, I’d use a generic list instead of an ArrayList and a class container rather than just arrays. Assuming you’re on .NET 3.5 or later, I’d suggest using LINQ for the sorting as well.
First, make a class container for the type of the menu items:
Then you can store instances of this class in a generic List:
Then, to sort this list by position, you can use LINQ: