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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T22:13:45+00:00 2026-06-06T22:13:45+00:00

I seem to have a problem passing some strings on from one form to

  • 0

I seem to have a problem passing some strings on from one form to another.
I have two listBoxes on Form1 but i want to use Form2 to pass the information on into the listBoxes in Form1.
In Form2 i have a button_Click function that calls a function in Form1 with params string a and string b.

private void button_Click(object sender, EventArgs e){
Form1 frm = new Form1();
frm.AddItemToListBox(txtBox1.Text,txtBox2.Text);
}

Below is the code to call the function AddItemToListBox in Form1.
Above is the function AddItemToListBox in Form1.

AddItemToListBox(string a, string b){
listBox1.Items.Add(a);
listBox2.Items.Add(b);
}

However this does not add the strings into the listboxes. There are no error messages or anything.
I have also tried declaring 2 public strings STR1 and STR2

AddItemToListBox(string a, string b){
listBox1.Items.Add(a);
listBox2.Items.Add(b);
STR1 = a;
STR2 = b;
}

But if i used a button that displays STR1 and STR2’s value. They will be “”, String.Empty. Nothing shows up in the MessageBox that displays the value. However, if i place the MessageBox.Show(a); and MessageBox.Show(b); in the AddItemToListBox function, the strings will be correctly shown but still not added to the listbox.

This has been frustrating me for like 2 hours now and i want to find out why and how to actually use that method to add an item to a listbox if its possible. Greatest thanks in advance.

  • 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-06T22:13:47+00:00Added an answer on June 6, 2026 at 10:13 pm

    Try to add a frm.Show() at the end of this method.

    private void button_Click(object sender, EventArgs e)
    { 
        Form1 frm = new Form1(); 
        frm.AddItemToListBox(txtBox1.Text,txtBox2.Text); 
        frm.Show();
    } 
    

    But I’m sure that this doesn’t solve your problem. Just show you that you need to reference the correct Form1. I think you are creating a new instance of Form1, yuo need to address the correct one

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

Sidebar

Related Questions

I have problem passing a variable from a main page containing a user control
I've been having this problem a lot recently in some form or another. Lets
I seem to have a problem with getting MVC to fill in my custom
I seem to have a problem understanding how to conditionally test a boolean value
I seem to have a tricky problem since the latest ADT update to release
I have a problem which I cant seem to find answer to through searches
I have a problem which i can't seem to find the solution to. I
I seem to have the exact opposite problem than this question on stopping dock
I have a problem with my cfml code. The ListAppend() function doesn't seem to
I have a small problem which i can't seem to figure out. I tried

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.