Find Position of an Item in a List- First, Last
<p>I am currently working with list of items loaded at the start of the program. I am trying to determine the position of each item. So I have button <code>First</code> which shows first item(Current), <code>Next</code> which shows the following items after first (Current.Next), <code>Last</code> which should show last itme but it is not displaying anything at all. The result is displayed after the button clicks on a label called <code>labelSpecificTree</code>. I tried setting a break inside <code>Last</code> button click line <code>Current = Trees.Last;</code> to see a result but doesn’t give me any specific details. How can I display through the label the last item on the list?</p>

<p><strong>Code</strong></p>

<pre><code>namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }


        ListOfTrees Trees = new ListOfTrees();
        FruitTrees Tree;
        FruitTrees Current;

        double Total;



        public class ListOfTrees
        {
            private int size;

            public ListOfTrees()
            {
                size = 0;
            }

            public int Count
            {
                get { return size; }
            }

            public FruitTrees First;
            public FruitTrees Last;

             public int Add_Initialize(FruitTrees NewItem)
             {
                 NewItem.Next = First;
                 First = NewItem;
                 Last = First.Next;

                 if (Last == null)
                 {
                     Last = First;
                 }

                 return size++;
             }

            public int Add(FruitTrees newItem)
            {
                if (First == null)
                    return Add_Initialize(newItem);

                FruitTrees item = First;
                while (item.Next != null)
                {
                    item = item.Next;
                }

                item.Next = newItem;
                return size++;
            }



        }




        public void Clear()
        {
            textBoxType.Clear();
            textBoxHeight.Clear();
            textBoxPrice.Clear();
            textBoxStock.Clear();
        }


        public void Current_Tree()
        {
            Current = Trees.First;
            labelSpecificTree.Text = Current.Type.ToString();
        }


        private void Form1_Load_1(object sender, EventArgs e)
        {

            Tree = new FruitTrees();
            Tree.Stock = 15;
            Tree.Type = "Pear";
            Tree.Price = 49.99;
            Tree.Height = 20;
            Total += Tree.Price * Tree.Stock;
            Trees.Add(Tree);

            ShowTrees();
            Current_Tree();
        }


        private void buttonLast_Click(object sender, EventArgs e)
        {
            Current = Trees.Last;
            labelSpecificTree.Text = Current.Type.ToString();
        }
    }
}
</code></pre>
