tags:

views:

78

answers:

2

I need to keep track of how many items are in a node of this one attribute in C# and I have no idea on how to load an array, starting with 1 and ending with a variable

The code for this portion is this

//Loads file containing OSXInstaller File List
doc.Load("Distribution.xml");
XmlNodeList ChoiceNode = doc.GetElementsByTagName("choice");
foreach (XmlNode choices in ChoiceNode)
{
    //Code Executed only  for packages, not categories
    if (choices.HasChildNodes == true)
    {
        choicetitle.Add(choices.Attributes["title"].InnerText);
        //Counts the number of items with an attribute of "title" in the 
        //distributions file, so if the user selects #1 in the list box it will 
        //know what number one is
        choicelistcount++;
    }
    if (choices.HasChildNodes == false)
    {
    }
    else
    {
        MessageBox.Show("Your Mac OS X Installation disk is damaged or was mounted improperly, please try again and doube-check your information!");
    }
}

I'm trying to get it to count the number of items with the attribute of title, then being able to print out all of the items in the list

choicetitle is the string list

I want it to look something like:

listBox1.Items.Add(choicetitle[1-choicetitlecount]);

edit: To answer some of the comments below;

I put this together in a very short time and things like spell-checking don't really matter to me

The reason why I also include an else statement is because it adds an additional check whether the OSX Install Disk was mounted

The Program is a tool to Add & Remove packages to the OSX Installer, not as in a live-cd type thing but to add packages that you can install onto your new OS X installation website is at http://osxreformer.org

+2  A: 

Your question is unclear, but you probably want to use the List<T> class, which can hold any number of elements.

You can create a List<SomeType>, and then add as many SomeType objects to it as you want, without worrying about size or capacity. (unless you run out of memory)

SLaks
A: 

You need to loop through part of your list, like this:

for(int i = 1; i < choicetitlecount; i++)
    listBox1.Items.Add(choicetitle[i]);

Note that .Net arrays and collections are 0-based, so unless you want to skip the first item, you probably want to start at 0. (change int i = 1 to int i = 0)


In general, you should give meaningful names to your controls (except labels). For example, you might want to rename listBox1 to choiceTitleList.

SLaks