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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T02:10:55+00:00 2026-05-14T02:10:55+00:00

I have created a form that is used for both adding and editing a

  • 0

I have created a form that is used for both adding and editing a custom object. Which mode the form takes is provided by an enum value passed from the calling code. I also pass in an object of the custom type. All of my controls at data bound to the specific properties of the custom object. When the form is in Add mode, this works great as when the controls are updated with data, the underlying object is as well. However, in Edit mode, I keep two variables of the custom object supplied by the calling code, the original, and a temporary one made through deep copying. The controls are then bound to the temporary copy, this makes it easy to discard the changes if the user clicks the Cancel button. What I want to know is how to persist those changes back to the original object if the user clicks the OK button, since there is now a disconnect because of the deep copying. I am trying to avoid implementing a internal property on the Add/Edit form if I can. Below is an example of my code:


public AddEditCustomerDialog(Customer customer, DialogMode mode)
{
   InitializeComponent();
   InitializeCustomer(customer, mode);
}
private void InitializeCustomer(Customer customer, DialogMode mode)
{
   this.customer = customer;
   if (mode == DialogMode.Edit)
   {
      this.Text = "Edit Customer";
      this.tempCustomer = ObjectCopyHelper.DeepCopy(this.customer);
      this.customerListBindingSource.DataSource = this.tempCustomer;
      this.phoneListBindingSource.DataSource = this.tempCustomer.PhoneList;
   }
   else
   {
      this.customerListBindingSource.DataSource = this.customer;
      this.phoneListBindingSource.DataSource = this.customer.PhoneList;
   }
}
  • 1 1 Answer
  • 2 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-14T02:10:56+00:00Added an answer on May 14, 2026 at 2:10 am

    You could always add a function to your object (Customer), either as “Copy(Customer cust)” or “Update(Customer cust)” and consume the changes that way.

    The other way would be to have a wrapper class around Customer EditableCustomer, which takes a customer object in its constructor EditableCustomer(Customer root) and uses that to hold the changes. In the final event just call a function like “UpdateRoot()” and populate the changes back to the original customer, failing to call this will be the same as a discard.

    You wont be able to use deep copies directly but this will allow you to control this type of situation, and actually allow you to control both edits and undo’s dynamically.

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

Sidebar

Related Questions

I have created a form that contains fields used to accept a floating value
I have created a macro for excel which will pop up form that contains
I've created an app which contains form and that have to filled up in
I have created a list form that gets attached to a main form in
I have created a form with knockout that will allow the ability to give
if i have created a view model and have a partial form that is
I have created a non-form c# program that uses the NotifyIcon class. The text
I have a form that is dynamically created, on this form are several radio
I have a textbox in a form that I created. I want to add
I have a model Product that is both used by a general controller products_controller

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.