How can I keep object from passing to another form?

Jack Nelson

I'm using ObjectListView and the object I'm adding to it is a custom Class that I've built for it.

My Class contains information for doing calculations. I want to allow users to be able to edit calculations they've already made.

I've tried pulling the object from the ObjectListView with the following different code:

Customer customer = (Customer)listCustomers.SelectedItem.RowObject;

Customer customer = (Customer)listCustomers.GetSelectedObject();

Customer customer = (Customer)listCustomers.SelectedObject;

All of those methods result in the customer to become that object. The problem I'm facing though, is if I change any of the values of that class, such as the following code, it reflects the change in that object in the ObjectListView:

customer.TotalValue += 50;

And even if I run those calculations on another form, by transferring that information via:

EditCustomer editForm = new EditCustomer(customer)
editForm.Show();

It still changes the object in the ObjectListView.

What I'm wondering, is how can I extract that object, and allow me to edit the customer object, while not changing the object in the ObjectListView?

Paul

Your customer variable is a reference to the object stored in your ObjectListView, so when you modify customer, the change is reflected in the underlying object it is referencing. When you pass customer to a different form, you are passing the reference, still pointing to the same underlying object, so that object can then be modified through that reference, even from a different form.

To get the behavior you want, you need to clone your object, making a completely separate copy of it, and then making changes to the copy will not impact the original.

Check here for information on cloning objects.

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

How can I keep the bubble from a JRadioButton when adding an ImageIcon?

분류에서Dev

How do I return an object from another model in a scope?

분류에서Dev

How can I change my number validation from a form to a prompt?

분류에서Dev

How do I keep a UILongPressGestureRecognizer active while switching from a UIViewController to another

분류에서Dev

(How) Can I get GUID from an IWbemClassObject object?

분류에서Dev

How can I keep a Status Bar from covering my RichTextBox...? C#

분류에서Dev

How can I keep the trailing slash after choosing a directory from the zsh completion options?

분류에서Dev

What am I doing wrong in returning a custom object to a mule flow and How do I return an object that can be consumed by another mule flow?

분류에서Dev

How can I access request object in django model admin change_form.html?

분류에서Dev

How can I do an array of object of my class (with inheritance of another custom class)?

분류에서Dev

How do I set the value of my field so that I can call it from another class?

분류에서Dev

How to access variable from another class directly(i.e. without using class name or object)?

분류에서Dev

How to find values from another JSON object

분류에서Dev

How can I match a user id value from a form input to records in my database?

분류에서Dev

How can i echo a variable posted from a textbox form using php?

분류에서Dev

How can I copy a text file into another?

분류에서Dev

How can I use another drive with Owncloud?

분류에서Dev

How can I refer a launchpad ppa in another?

분류에서Dev

How can i download youtube videos one after another automatically from terminal

분류에서Dev

In my SQL query, how can I have a column with values queried from another table?

분류에서Dev

How can I create a column of dummy variables ranging from 1-4 based on another column?

분류에서Dev

How do I can change contents of some div sections while clicking text from another div

분류에서Dev

How can I copy HTML textbox values from one domain to another domain's textboxes?

분류에서Dev

How can I copy locations from one campaign to another in Google Adwords?

분류에서Dev

How can I create SQL that does a Left Outer Join and also a count from another table?

분류에서Dev

How can I read a text file from the terminal and save the output to another file in java?

분류에서Dev

How can I post data to another file and render from it using DomPDF

분류에서Dev

How can i get from the List<string> of files each time another file?

분류에서Dev

How can I open another app made for me from webintent in phonegap?

Related 관련 기사

  1. 1

    How can I keep the bubble from a JRadioButton when adding an ImageIcon?

  2. 2

    How do I return an object from another model in a scope?

  3. 3

    How can I change my number validation from a form to a prompt?

  4. 4

    How do I keep a UILongPressGestureRecognizer active while switching from a UIViewController to another

  5. 5

    (How) Can I get GUID from an IWbemClassObject object?

  6. 6

    How can I keep a Status Bar from covering my RichTextBox...? C#

  7. 7

    How can I keep the trailing slash after choosing a directory from the zsh completion options?

  8. 8

    What am I doing wrong in returning a custom object to a mule flow and How do I return an object that can be consumed by another mule flow?

  9. 9

    How can I access request object in django model admin change_form.html?

  10. 10

    How can I do an array of object of my class (with inheritance of another custom class)?

  11. 11

    How do I set the value of my field so that I can call it from another class?

  12. 12

    How to access variable from another class directly(i.e. without using class name or object)?

  13. 13

    How to find values from another JSON object

  14. 14

    How can I match a user id value from a form input to records in my database?

  15. 15

    How can i echo a variable posted from a textbox form using php?

  16. 16

    How can I copy a text file into another?

  17. 17

    How can I use another drive with Owncloud?

  18. 18

    How can I refer a launchpad ppa in another?

  19. 19

    How can i download youtube videos one after another automatically from terminal

  20. 20

    In my SQL query, how can I have a column with values queried from another table?

  21. 21

    How can I create a column of dummy variables ranging from 1-4 based on another column?

  22. 22

    How do I can change contents of some div sections while clicking text from another div

  23. 23

    How can I copy HTML textbox values from one domain to another domain's textboxes?

  24. 24

    How can I copy locations from one campaign to another in Google Adwords?

  25. 25

    How can I create SQL that does a Left Outer Join and also a count from another table?

  26. 26

    How can I read a text file from the terminal and save the output to another file in java?

  27. 27

    How can I post data to another file and render from it using DomPDF

  28. 28

    How can i get from the List<string> of files each time another file?

  29. 29

    How can I open another app made for me from webintent in phonegap?

뜨겁다태그

보관