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 7001753
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:50:35+00:00 2026-05-27T20:50:35+00:00

I am asked to write a separate class to do something, so I figured

  • 0

I am asked to write a separate class to do something, so I figured I would do this for a to-do list (use a text box to enter data into a list and then have another list for completed tasks, use a button to transfer between).

I have been able to get data added into my to-do list and my code will successfully remove from the to-do list and place in the “Done” list through clicking a button.

My code doesn’t work when I put it in a new class.

Here’s the code of the new class:

public class ToDo : Form1

    {
        public void Remove()
        {

            for (int i = 0; i <= (lstToDo.SelectedItems.Count - 1); i++)
            {

                lstDone.Items.Add(lstToDo.SelectedItems[i]);
                lstToDo.Items.Remove(lstToDo.SelectedItems[i]);

            }
        }
    }

and here is the code from Form1 which I think I am attempting to call from when I click on a button:

public void btnRemoveToDo_Click(object sender, EventArgs e)
        {

            ToDo todo = new ToDo();
            todo.Remove();
        }

Any help?

  • 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-05-27T20:50:36+00:00Added an answer on May 27, 2026 at 8:50 pm

    Before you moved it into the new class, I imagine your method looked like…

    public void btnRemoveToDo_Click(object sender, EventArgs e)
    {
        this.Remove();
    }
    

    When you moved it into a new class, you changed that code to…

    ToDo todo = new ToDo();
    todo.Remove();
    

    That is creating a new instance of the class. To make it work, you would have to use the existing instance; this like so…

    ToDO todo = (ToDo) this;
    todo.Remove();
    

    This isn’t really optimal either though because it is a very awkward architecture. You are better to leave methods which utilize components of the form on the form class itself. If you want methods to process the data, extract the values out of the Form’s components and then use the data as parameters to different classes’ methods. That is more of a comment on general software architechture though and not really important to your specific problem.

    EDIT
    Casting the Form instance (this) as a ToDo instance won’t work because Form1 does not inherit from ToDo as commented on.

    You are better off moving the Remove() method back into Form1 class for now. My suggestion would be to try to learn a little bit more about Objects and Object Oriented Programming (OOP) before attempting to break out anything else into different classes.

    The other thing you could try is making the Remove() method on the ToDo class take in anything it needs as parameters.

    public void Remove(ListControl todoList, ListControl doneList)
    {
        for (int i = 0; i <= (todoList.SelectedItems.Count - 1); i++)
        {
            doneList.Items.Add(todoList.SelectedItems[i]);
            todoList.Items.Remove(todoList.SelectedItems[i]);
        }
    }
    

    Then you would have to make your other method look like this…

    public void btnRemoveToDo_Click(object sender, EventArgs e)
    {
        ToDo toDo = new ToDo();
        toDo.Remove(lstToDo, lstDone);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Previously I asked about how I could call separate values from a text file
I've just been asked to write an SSRS report that displays data like so:
In a past interview, I was asked how would I write a mission critical
I was asked to write a fib function in the most efficient manner? This
This is an interview Question that i was asked recently: Write a C program
I was recently asked to write 3 test programs for a job. They would
Hey, I have been asked to write a recursive binary search for my data
I've been asked to write a Windows service in C# to periodically monitor an
I have been asked to write an app which screen scrapes info from an
I was asked to write a servlet that collects client's details such as ip,

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.