Current filter:
          You should refresh the page.
          Not Logged In

          How to view persistent objects in the XtraGrid and edit them in a separate window

          0

          This example demonstrates how to edit XPO objects in the scope of a UnitOfWork, so that the changes made to the object's properties can be saved or canceled.

          See Also:
          XPO Best Practices

          You must  log in  or  register  to leave comments
          Select file
          • FormEditOrder.cs
          • FormViewOrders.cs
          • PersistentObjects.cs
          • Program.cs
          Select language
          • C#
          • VB.NET
          Select version
          • v2007 vol 3.12 - v2012 vol 1.2
          using System;
          using System.Collections.Generic;
          using System.ComponentModel;
          using System.Data;
          using System.Drawing;
          using System.Text;
          using System.Windows.Forms;
          using DevExpress.Xpo;
          
          namespace XpoEditForm
          {
              public partial class FormEditOrder : Form
              {
                  private Order sourceOrder, theOrder;
                  private XPCollection sourceCollection;
          
                  public FormEditOrder(Order order, XPCollection collection)
                  {
                      this.sourceOrder = order;
                      this.sourceCollection = collection;
          
                      InitializeComponent();
          
                      if(sourceOrder == null)
                          theOrder = new Order(unitOfWork1);
                      else
                          theOrder = unitOfWork1.GetObjectByKey<Order>(sourceOrder.Oid);
          
                      xpCollection1.Add(theOrder);
                      gridControlOrderDetails.DataSource = theOrder.OrderDetails;
                  }
          
                  private void btnCancel_Click(object sender, EventArgs e)
                  {
                      Close();
                  }
          
                  private void btnOK_Click(object sender, EventArgs e)
                  {
                      gridView1.UpdateCurrentRow();
                      BindingContext[xpCollection1].EndCurrentEdit();
                      
                      if(unitOfWork1.InTransaction) {
                          unitOfWork1.CommitChanges();
                          if(sourceOrder == null)
                              sourceCollection.Reload();
                          else
                              sourceOrder.Reload();
                      }
                      Close();
                  }
              }
          }