We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Modifying other column values while validating data in CurrentCellEndEdit

Creating a simple order entry system.   Want to auto-calculate totals in row as data is entered.


Data source is a simple ObservableCollection of OrderLineItem defined as follows:

        public class OrderLineItem

        {

            public string OrderID { get; set; }

            public object CustomerID { get; set; }

            public string CustomerName { get; set; }

            public string Description { get; set; }

            public string VendorPart { get; set; }

            public double Quantity { get; set; }

            public double UnitCost { get; set; }

            public double UnitResale { get; set; }

            public double TotalCost { get; set; }

            public double TotalResale { get; set; }

            public Boolean Combine { get; set; }

            public Boolean Reimburse { get; set; }


        }


Code looks like this so far:


   private void dataGridLineItems_CurrentCellEndEdit(object sender, Syncfusion.SfDataGrid.XForms.GridCurrentCellEndEditEventArgs e)

        {

            switch (e.RowColumnIndex.ColumnIndex)

            {


                case 4:

                    OrderLineItem record = (OrderLineItem)dataGridLineItems.GetRecordAtRowIndex(e.RowColumnIndex.RowIndex);

                    //Unit Cost

                    Double Quantity = 0.0;

                    try { Quantity = record.Quantity; } catch { }

                    Double UnitCost = 0.0;

                    try { UnitCost = record.UnitCost; } catch { }

                    Double TotalCost = Quantity * UnitCost;

                    record.TotalCost = TotalCost;

                    break;

                case 5:

                    //Unit Retail

                    break;


                case 6:

                    //Unit Quantity

                    break;

            }


        }


New value of TotalCost is not shown in the grid.   Do I need to do something to notify the grid that the value has changed?   



1 Reply

SV Suja Venkatesan Syncfusion Team February 13, 2023 01:39 PM UTC

Hi Paul,


We have checked provided code snippets on our end. You can resolve the reported issue by implementing the INotifyPropertyChanged interface for the Model class property to reflect the UI view changes like the code snippet below. The INotifyPropertyChanged interface is used to notify clients, typically binding clients, that a property value has changed.


Code Snippet:

   public class OrderLineItem:INotifyPropertyChanged

    {

        string orderID;

        double totalcost;

 

        public string OrderID

        {

            get { return orderID; }

            set { orderID = value;

                RaisePropertyChanged("OrderID");

            }

        }

        public double TotalCost

        {

            get { return totalcost; }

            set

            {

               totalcost = value;

                RaisePropertyChanged("TotalCost");

            }

        }

        #region INotifyPropertyChanged

        public event PropertyChangedEventHandler PropertyChanged;

        private void RaisePropertyChanged(string name)

        {

            if (PropertyChanged != null)

                this.PropertyChanged(this, new PropertyChangedEventArgs(name));

        }

        #endregion

    }

Please let us know if you need any further assistance.


Regards,

Suja


Loader.
Up arrow icon