calculation not shown when cell edit cancel true

Dear Sir 

I had a problem when i calculate the Column i.e (qty * rate) = GrossAmount

i wanted that user cannot edit the GrossAmount Column so i use `Cell Edit` Event . Event working properly but it cant show me value in Gross Amount Column when i put (qty and Rate) if i remove my event it show.

But i wanted to user cannot use this GrossAmount Column to Edit.

Which i Event use i describe you below : -

'''''' This Event i use for calculation

private void CellSaved(CellSaveArgs<LedgerAccounts> args)

    {

        args.Data.GrossAmount = args.Data.Qty * args.Data.Rate;



        Grid.UpdateCell(Grid.SelectedRowIndex, "GrossAmount", args.Data.GrossAmount);


        if(args.Data.DiscPer > 0)

        {

            args.Data.DiscAmount = (args.Data.GrossAmount * args.Data.DiscPer)/100;

        }


        args.Data.NetAmount = args.Data.GrossAmount - args.Data.DiscAmount;

        Grid.UpdateCell(Grid.SelectedRowIndex, "NetAmount", args.Data.NetAmount);

    }


''''' Now this Event I use for not Edit in Gross Amount Column

public void CellEditHandler(CellEditArgs<LedgerAccounts> args)

    {

        if (args.ColumnName == "GrossAmount")

        {

            args.Cancel = true;



            // Grid.Refresh();

        }

    }


1 Reply

MS Monisha Saravanan Syncfusion Team February 22, 2022 11:42 AM UTC

Hi Asif, 

Greetings from Syncfusion support. 

We have analyzed your query and instead of using UpdateCell method we suggest you to use SetRowDataAsync method to update the edited data to the DataGrid. Kindly check the attached code snippet for your reference. 

 
<SfGrid DataSource="@Orders" @ref="Grid" Toolbar="@(new List<string>() { "Add", "Delete", "Update", "Cancel" })"> 
    <GridEvents CellSaved="CellSavedHandler" OnCellEdit="CellEdit" TValue="Order"></GridEvents> 
    <GridEditSettings AllowAdding="true" AllowEditing="true" AllowDeleting="true" Mode="EditMode.Batch"></GridEditSettings> 
    <GridColumns> 
...   
    </GridColumns> 
</SfGrid> 
 
@code{ 
    public List<Order> Orders { get; set; } 
    public SfGrid<Order> Grid; 
 
    public void CellSavedHandler(CellSaveArgs<Order> args) 
    { 
        args.Data.GrossAmount = args.Data.Quantity * args.Data.Rate; 
        var primarykey = args.Data.GetType().GetProperty("OrderID").GetValue(args.RowData); 
        Grid.SetRowDataAsync(primarykey, args.Data); 
 
        //Grid.UpdateCell(Grid.SelectedRowIndex, "GrossAmount", args.Data.GrossAmount); 
    } 
    public void CellEdit(CellEditArgs<Order> args) 
 
    { 
 
        if (args.ColumnName == "GrossAmount") 
 
        { 
 
            args.Cancel = true; 
 
        } 
 
    } 
} 


Kindly get back to us if you have further queries. 

Regards, 
Monisha 


Loader.
Up arrow icon