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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T04:52:07+00:00 2026-06-01T04:52:07+00:00

I have 2 forms in C# desktop application. Form1 and Form2. Form1 contains a

  • 0

I have 2 forms in C# desktop application. Form1 and Form2.

Form1 contains a public method that adds item in ListBox control as follows:

public void AddToList(string item)
{
    listBox.Items.Add(item);
}

When I call this method directly on some button press then it works fine. But when I call this method from Form2, it doesn’t add anything in ListBox control on Form1. Code in Form2 is as below:

Form1 frm = new Form1();
frm.AddToList("something");

When I run this nothing happens. No error nothing. It just doesn’t add any item into ListBox.

What am I doing wrong?

  • 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-01T04:52:08+00:00Added an answer on June 1, 2026 at 4:52 am

    You’re creating a new instance of Form1 and adding an item to it’s listbox, rather than getting an instance of the Form1 you no doubt already have and calling the method on that.

    The naive approach is to have a parameter in the Form2 constructor that takes an instance of Form1 and saves it as an instance variable for use in this event handler.

    I don’t much like that approach from a design perspective.

    I would suggest creating a public event in Form2, having Form1 subscribe to that event and add a handler that add the item to the listbox. The Event in Form2 would look something like this:

    public event EventHandler ButtonClick
    {
        add
        {
            button1.Click += value;
        }
        remove
        {
            button1.Click += value;
        }
    }
    

    Then you’ll have a property that looks something like this:

    public string SomeValueForm1NeedsOnButtonClick
    {
        get
        {
            return texbox1.Text;
        }
    }
    

    Then in Form1 you’ll have something like:

    Form2 otherForm = new Form2();
    otherForm.ButtonClick += (sender, args) =>
    {
        listbox1.Items.Add(otherForm.SomeValueForm1NeedsOnButtonClick);
    };
    

    This approach ensures that each form only knows as little as possible about each other form. It reduces Coupling between the two classes and makes it clearer to future users/readers of the forms exactly what communication takes place between them.

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

Sidebar

Related Questions

I have a Windows.Forms based .NET desktop application that stores privileged information in a
I also have a desktop application written in Windows Forms that is a middling
I have a Windows Forms application that runs locally on the user's desktop. The
In a typical business application it is quite common to have forms that are
I have a desktop forms application . I want to fetch any flash file
We have a desktop application that has been using MapPoint for displaying data on
I have question I'm developing small application to desktop in win Forms. I'm using
I have a application in which i have several forms. In that forms, I
I have a desktop application that on first execution prompts for the connection details
I have written a Windows Forms application in C#, .NET framework 2.0, that uses

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.