Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
325
Clone Dragged DataItem
posted

Hello,

We have two XamDataGrids setup as treeviews.

We are draging and dropping from one to the other.

We only allow one to have records deleted.

But when you delete a record from one, it gets deleted from the other.

 

I have tryed to clone the object, but I cannot find any mothod of doing so through out the datagrid's members.

 

        private void dgRight_Drop(object sender, DragEventArgs e)
        {
            XamDataGrid dragSource = dgLeft;
            XamDataGrid dragTarget = sender as XamDataGrid;

            //Get Instance of the dragger DataRecordPresenter and DataRecord
            DataRecordPresenter draggedPresenter = e.Data.GetData(typeof(DataRecordPresenter)) as DataRecordPresenter;
            DataRecord draggedRecord = draggedPresenter.Record as DataRecord;

            dragTarget.DataItems.Add(draggedRecord.DataItem);
        }

 

How do we copy the DataItem over without it being tied to the source?

If this is not possible, what is the best method of dragging items from one grid to the other, while allowing only one to have items deleted without affecting the source?

 

Thanks,

-Matt.

Parents
No Data
Reply
  • 69686
    posted

    Hello Matt,

    I apologize that this post was not answered sooner. We are making the effort to ensure all posts are addressed by an Infragistics expert.

    You can create a deep copy of the dragged item. The easiest way by me is using serialization (BinaryFormatter). For example:

    public TestClass Copy()
    {
      MemoryStream memoryStream = new MemoryStream();
      BinaryFormatter binaryFormatter = new BinaryFormatter();
      
      binaryFormatter.Serialize(memoryStream, this);
      memoryStream.Seek(0, SeekOrigin.Begin);
    
      return (TestClass)binaryFormatter.Deserialize(memoryStream);
    }

    Thank you!

Children
No Data