0

Hi...
I have a fixed size array in my program.....
but in order to make the program memory efficient....
i want to make it an ArrayList...
can someone please explain how to do this.....
i have posted my code below...

class StaticColumn
    {
        public TextBox[] textBoxes = new TextBox[1000];

        public void getDetails(XmlNode node)
        {
            XmlElement nodeAsElement = node as XmlElement;
            XmlNodeList _list = nodeAsElement.GetElementsByTagName("Textbox");
            int i=0;
            foreach (XmlNode tempNode in _list)
            {
                textBoxes[i] = new TextBox();
                textBoxes[i].getDetails(tempNode);
                i++;
            }

                                    
        }
    }
class TextBox
    {
        public string name = string.Empty;
        public string value = string.Empty;
        public string visibility = string.Empty;
        public Navigation navigation = new Navigation();

        public void getDetails(XmlNode node)
        {
            XmlElement nodeAsElement = node as XmlElement;

            try { name = node.Attributes["Name"].InnerText.ToString(); }
            catch (NullReferenceException e)            {            }

            try { value = nodeAsElement.GetElementsByTagName("Value")[0].InnerText.ToString(); }
            catch (NullReferenceException e) { }

            try { visibility = nodeAsElement.GetElementsByTagName("Visibility")[0].InnerText.ToString(); }
            catch (NullReferenceException e) { }

            try { visibility = nodeAsElement.GetElementsByTagName("Hidden")[0].InnerText.ToString(); }
            catch (NullReferenceException e) { }

            try
            {
                navigation = new Navigation();
                node = nodeAsElement.GetElementsByTagName("Drillthrough")[0];
                navigation.getDetails(node);
            }
            catch (NullReferenceException e) { navigation = null; }
            
        }

        public void getElements(XmlNode node)
        {
            XmlElement nodeAsElement = node as XmlElement;

            try { name = node.Attributes["Name"].InnerText.ToString(); }
            catch (NullReferenceException e) { }

            try { visibility = nodeAsElement.GetElementsByTagName("Visibility")[0].FirstChild.InnerText.ToString(); }
            catch (NullReferenceException e) { }

            //try { visibility = nodeAsElement.GetElementsByTagName("Hidden")[0].InnerText.ToString(); }
            //catch (NullReferenceException e) { }

            try
            {
                navigation = new Navigation();
                node = nodeAsElement.GetElementsByTagName("Drillthrough")[0];
                navigation.getDetails(node);
            }
            catch (NullReferenceException e) { navigation = null; }

            try
            {
                nodeAsElement = (XmlElement)nodeAsElement.GetElementsByTagName("Paragraphs")[0];
                XmlNodeList _list1 = nodeAsElement.GetElementsByTagName("Value");
                foreach (XmlNode tempNode in _list1)
                {
                    value = value + tempNode.InnerText.ToString();
                }
            }
            catch (NullReferenceException e) { }
        }

    }

i also want to know how to read from the new class .. Because i'm sure the changes would also affect the reading...

2
Contributors
6
Replies
7
Views
5 Years
Discussion Span
Last Post by arjunpk
Featured Replies
  • check these link may be helpful [URL="http://www.dotnetperls.com/arraylist"]1st link[/URL]....[URL="http://www.dotnetperls.com/convert-list-array"] 2nd link[/URL] Read More

  • Have you checked [URL="http://www.techotopia.com/index.php/C_Sharp_List_and_ArrayList_Collections"] this one[/URL]? and [URL="http://www.techotopia.com/index.php/C_Sharp_List_and_ArrayList_Collections"]this one[/URL]....and [URL="http://www.programmingforums.org/thread18796.html"]this[/URL].... actually I ddn't understand you question so giving you these links that might be helpful in understanding the core of arraylist Read More

0

check these link may be helpful 1st link.... 2nd link

hi...
i have already seen these links....
what i need is to create array list of custom classes.....
thanks anyways....

0

check these link may be helpful 1st link.... 2nd link

what i mean is i need a more detailed explanation.....
the explanation given there is quite simple and it is for a simple list....
i want to know how to do it wen i am doing it with a custom class with lots of variables...
like the example i posted.....

0

what i am asking is......
if i have to make :-

public TextBox[] textBoxes = new TextBox[1000];

AS

public List<TextBox> textBoxes = new List<TextBox>();

what are the changes i'll have to make to the textbox class to read and write data.....

0

I have found a solution....
All i have to do is this...

class StaticColumn
    {
        public System.Collections.ArrayList textBoxes = new System.Collection.ArrayList();

        public void getDetails(XmlNode node)
        {
            XmlElement nodeAsElement = node as XmlElement;
            XmlNodeList _list = nodeAsElement.GetElementsByTagName("Textbox");
            int i=0;
            foreach (XmlNode tempNode in _list)
            {
                TextBox t = new TextBox();
                t.getDetails(tempNode);
                textBoxes.Add(t);
            }

                                    
        }
    }
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.