I am working with a link list. The list is brought up on the form load (size, height, stock, price) displayed in a multiline textbox called textBoxResults. I have three button called First, Next and Last. Naming convention is straightforward, button First click displays first tree, Next, displays each item after first through each button click and Last button shows the last item on list. First works fine but Second only shows the following item after first and gives up, Last displays weird result WindowsFormsApplication1.Form1+Fruit Trees. How can I display the proper tree name according to its position through the button clicks?
Code
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public class ListOfTrees
{
private int size;
public ListOfTrees()
{
size = 0;
}
public int Count
{
get { return size; }
}
public FruitTrees First;
public FruitTrees Last;
}
public void ShowTrees()
{
}
public void Current_Tree()
{
labelSpecificTree.Text = Trees.First.Type.ToString();
}
private void Form1_Load_1(object sender, EventArgs e)
{
}
private void buttonFirst_Click(object sender, EventArgs e)
{
Current_Tree();
}
private void buttonNext_Click(object sender, EventArgs e)
{
Current = Trees.First;
labelSpecificTree.Text = Current.Next.Type.ToString();
}
private void buttonLast_Click(object sender, EventArgs e)
{
Current = Trees.Last;
labelSpecificTree.Text = Trees.Last.ToString();
}
}
}
Several problems in your code (see the comments for corrections):
Secondly in your Next method:
And in the “last” method:
And of course the current method is broken, also…