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

  • Home
  • SEARCH
  • 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 7587043
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T19:34:33+00:00 2026-05-30T19:34:33+00:00

Here are all my classes. MainForm = listview, CustomerFrame = textboxes When I compile

  • 0

Here are all my classes.

MainForm = listview,

CustomerFrame = textboxes

When I compile my program, my MainForm appears with an empty listview, and when I press on the add button to insert an item, my CustomerFrame class appears. When writing in the textboxes and clicking ok, no item inserted in my listview (MainForm). Why?

Some code:

MainForm

using(var customerframe = new CustomerFrame())
{   
    if (customerframe.DialogResult == DialogResult.OK) 
    {
        CustomerFiles.Contact contact = customerframe.GetContact();
        CustomerFiles.Address address = customerframe.GetAddress();
        CustomerFiles.Phone phone = customerframe.GetPhone();
        CustomerFiles.Email email = customerframe.GetEmail();

        //Items in my listview
        listviewitem = new ListViewItem();
        listviewitem.SubItems.Add(contact.FirstName);
        listviewitem.SubItems.Add(contact.LastName);
        listviewitem.SubItems.Add(phone.Home);
        listviewitem.SubItems.Add(phone.Mobile);
        listviewitem.SubItems.Add(address.Country);
        listviewitem.SubItems.Add(address.ZipCode);
        listviewitem.SubItems.Add(address.City);
        listviewitem.SubItems.Add(address.Street);
        listviewitem.SubItems.Add(email.Personal);

        this.listView1.Items.Add(listviewitem);

    }
}

MainForm

private void addToolStripMenuItem_Click_1(object sender, EventArgs e)
{
    customerframe.Show();
    CustomerManager cm = new CustomerManager();
}

CustomerFrame

private void btnOk_Click(object sender, EventArgs e)
{
    MainForm main = new MainForm();
    DialogResult = DialogResult.OK;        
}

By the way, when I use

 if (customerframe.ShowDialog() == DialogResult.OK)

this will make the CustomerFrame form appear before the MainForm (which I don’t want) and it will insert item, but only once.

  • 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-30T19:34:34+00:00Added an answer on May 30, 2026 at 7:34 pm

    Why do you open ANOTHER main form from DialogBox? I think that you should remove this line.

    MainForm main = new MainForm();
    

    And add this

    DialogResult = DialogResult.OK;
    Close();
    

    Argh, to simplify – code in ButtonOK should look like this:

    private void btnOk_Click(object sender, EventArgs e)
    {
       DialogResult = DialogResult.OK;
       Close();    
    }
    

    EDIT: response to new problem

    First create new CustomerFrame, show it and wait for it to close; then transfer new data to your ListView. I believe that your add handler should look like this:

    private void addToolStripMenuItem_Click_1(object sender, EventArgs e)
    {
        using(var customerframe = new CustomerFrame())
        {   
            // I don't know what this line does
            CustomerManager cm = new CustomerManager();
    
            if (customerFrame.ShowDialog() == DialogResult.OK) 
            {
                CustomerFiles.Contact contact = customerframe.GetContact();
                CustomerFiles.Address address = customerframe.GetAddress();
                CustomerFiles.Phone phone = customerframe.GetPhone();
                CustomerFiles.Email email = customerframe.GetEmail();
    
                //Items in my listview
                listviewitem = new ListViewItem();
                listviewitem.SubItems.Add(contact.FirstName);
                listviewitem.SubItems.Add(contact.LastName);
                listviewitem.SubItems.Add(phone.Home);
                listviewitem.SubItems.Add(phone.Mobile);
                listviewitem.SubItems.Add(address.Country);
                listviewitem.SubItems.Add(address.ZipCode);
                listviewitem.SubItems.Add(address.City);
                listviewitem.SubItems.Add(address.Street);
                listviewitem.SubItems.Add(email.Personal);
    
                this.listView1.Items.Add(listviewitem);
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My mappings are below. Here is the base class for all classes. There is
I have a problem with this code. You can find all classes here .
I have problem with constraints on generic method. Here is code for all classes:
I need to enumerate all classes in a package and add them to a
enter code here Hi All, I have a simple windows service application that connects
I have carried the method here on almost all of the areas where I
Here the total height of all <div> 's are 900 pixels, but the jQuery
Here's the goal: to replace all standalone ampersands with &amp; but NOT replace those
Here's a simple (hopefully) L10N question: Do all locales want this format: Sunday, Nov
Here is the problem: We have all of our development under subversion, but our

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.