assign object reference to another object

C

c_xyTopa

Hi all,

i have 2 Forms - ListView and DetailView.
By clicking any element of the ListView the clicked order-object is passed
to the DetailView, where it can be modified.
If the order is modified and than a "Cancel"-button clicked, you navigate
back to ListView.
As a result you see a modified order, wich was actualy not saved.

To avoid this I create a clone of the selected order and if a
"Cancel"-button is clicked and a clone is not the same as order I assign
clone to the order.
But still in the ListView i get the modified object...
What is the problem?

Thanx

--------------------OrderClass-----------------------------
public class Order : ICloneable
{
public object Clone()
{
Order clone = this.MemberwiseClone() as Order;
return clone;
}
public override bool Equals(object obj)
{ . }
}

--------------------OrderDetails-----------------------------

public partial class OrderDetails : Form
{
private Order _order;
private Order _clone;

public OrderDetails(Order order)
{
_order = order;
_clone = this._order.Clone() as Order;
InitializeComponent();
}

// close-btn
private void menuItem1_Click(object sender, EventArgs e)
{
if (!_order.Equals(_clone))
_order = _clone;

this.Close();
}
}
 
G

Guest

shallow copy creates a clone of the main (root) object, but doesn't create a
copy of any dependent object.

Check the clone method, do cloning not shaalow copy usign the MemberwiseClone.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top