Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8979531
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T19:52:07+00:00 2026-06-15T19:52:07+00:00

I am working with lists. I have been able to determine the first and

  • 0

I am working with lists. I have been able to determine the first and last position of items in my list. I am using getPostion and displaying item name through a Label. Three buttons in my form: ShowFirstItem ShowNextItem(not working) and ShowLastItem show the corresponding item in a label. I am having problems for my next item. I don’t have a member that is holding the current fruit_tree. So I am not sure how to either add an int member or another fruit_tree member called current. How would I be able to find out next (item after first) and display result?

 public class ListForTrees
 {

        public fruit_trees GetNextTree()
            {
                current = 0;
                fruit_trees ft = first_tree;
                int i = 0;
                while (i != current)
                {
                    ft = ft.next_tree;
                    i++;

                }

                return ft;
            }

            }

            ListForTrees mainlist = new ListForTrees();     

            private void BtnGo_Click(object sender, EventArgs e)
            {
                fruit_trees[] ar_items = {   new fruit_trees("cherry", 48, 12.95, 3),
                                                 new fruit_trees("pine", 36, 9.95, 8),
                                                 new fruit_trees("oak", 60, 14.95, 2),
                                                 new fruit_trees("peach", 54, 19.95, 3),
                                                 new fruit_trees("pear", 36, 11.85, 2),
                                                 new fruit_trees("apple", 62, 13.45, 5)
                                             };   
                mainlist = new ListForTrees(ar_items);
                fruit_trees current = mainlist.first_tree;   

                while (current != null)
                {
                    TxtOutput.AppendText(current.ToString() + Environment.NewLine);
                    current = current.next_tree;
                }
            }


            private void ShowFirstItem_Click_1(object sender, EventArgs e)
            {
            // Show First Item
        labelSpecificTree.Text = mainlist.first_tree.GetTreeType;

            } 

            private void ShowLastItem_Click(object sender, EventArgs e)
            {
            //Show Last Item
        labelSpecificTree.Text = mainlist.last_tree.GetTreeType;
            }

        private void ShowNextItem_Click(object sender, EventArgs e)
            {
            //Show Next Item
 fruit_trees obj = mainlist.GetNextTree();

            if (obj == null)
            {
                labelSpecificTree.Text = "No more trees!";
            }
            else
            {
                mainlist.current++;
                labelSpecificTree.Text = obj.next_tree.GetTreeType.ToString();                
            }   
            }



        }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T19:52:08+00:00Added an answer on June 15, 2026 at 7:52 pm

    I would add

    public int current; 
    

    to the listoftrees. in the constructor set it to 0;

    Then create a method to return the current fruit_trees object

    public fruit_trees getCurrent()
    {
        fruit_trees ft = first_tree;
        int i = 0;   
        while(i != current)
        {
           ft = ft.next_tree;
           i++;
        }
        return ft;
     }
    

    now this method returns the current and not the next object. So you have 2 options in the next button event.
    the quesiton here is do you want to move to the next tree object every time the button is clicked?
    if so increment the current property and then call getcurrent to display. If you want the current to be retained and not move (i.e. clicking next over and over will result in the same thing)
    then display getcurrent().next_tree.tree_type with no increment to current.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been working on a new style for my list boxes but I
I am working with amazon boto and I have 2 lists. List 1 contains
I have been working with the google docs api found here: https://developers.google.com/google-apps/documents-list/#introduction This issue
I have been able to find a command to get a list of the
I'm working on a navigation control. I have nested lists which creates this: What
I'm working with a demo of two sortable jquery lists... but have a problem
Hello I have this list that i am working on. When i move the
I have a recursive function working on a list, the function contains a loop
I'm working on a project that needs to have a list of weekdays. I
Still working on lisp recipes and idioms. I have a list like this: ((a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.