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.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Updating a Grid Summary Row value after editing the grid, when the summary row is the sum of an unbound column which uses an expression to obtain its values.

Thread ID:

Created:

Updated:

Platform:

Replies:

125434 Aug 17,2016 08:44 AM UTC Aug 22,2016 12:15 PM UTC WPF 5
loading
Tags: GridDataControl
Bruce Guthrie
Asked On August 17, 2016 08:44 AM UTC

hello
i am using a unbound column getting values by an expression (price*used) to give me a list of total cost. i then have a summary row which sums all my total costs to give an overall cost.

<syncfusion:GridDataUnboundVisibleColumn Expression="price*used" HeaderText="What if Cost"

MappingName="cost2" IsReadOnly="True">

i edit the price from say 10.00 to 12.00 and i get the correct new total cost in my unbound column.

Example

price used total price

10.00 5 50.00

edit price to 12.00

12.00 5 60.00 this works OK.

But the summary row does not update to reflect the new overall total cost (ie sum of the unbound column values.)

My data is in an observable collection which i set to the grid itemsource at load time.

i have tried using doubleaggregate and customaggregate to get the summary row to update but it does not update.

i hope i am missing something simple here.


regards

Bruce



Attachment: sync_GridDataControl_Summary_Row_139694e0.zip

Jai Ganesh S [Syncfusion]
Replied On August 18, 2016 01:11 PM UTC

Hi Bruce, 
 
You can achieve your requirement to updating the TableSummary for Unbound Column at runtime by using the below code, 
 
this.dataGrid.ItemsSourceChanged += dataGrid_ItemsSourceChanged; 
 
void dataGrid_ItemsSourceChanged(object sender, Syncfusion.Windows.ComponentModel.SyncfusionRoutedEventArgs args) 
{ 
    this.dataGrid.Model.View.RecordPropertyChanged += View_RecordPropertyChanged; 
} 
 
void View_RecordPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) 
{ 
    var updatetablesummarymethod = this.dataGrid.Model.View.GetType().GetMethods(System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).FirstOrDefault(methodinfo=> methodinfo.Name == "UpdateTableSummary" && methodinfo.GetParameters().Count() == 0); 
    updatetablesummarymethod.Invoke(this.dataGrid.Model.View, null); 
} 
 
 
Regards, 
Jai Ganesh S 


Bruce Guthrie
Replied On August 18, 2016 02:52 PM UTC

Hello

i tried this solution but i still cannot get the summary row to update with the new Sum Total Cost in the Summary row.

my summary row is in fact a Group Summary Row, your response indicates a TableSummary Row.  i don't know if that makes a big difference. and your solution uses UpdateTableSummary.

Anyway i tried the solution by attaching the ItemSourceChanged event but in my case this does not fire.  so i put the event into the CurrentCellEditComplete to get to fire the summary update code you supplied.  However even then the Group Summary row does not update.

i do see an UpdateSummaries in the Grid.Model.View.  but it contains an object[] as a parameter and i do not know what to pass in for this.

My observable collection is obtained from loading the data into a datatable then i loop the DT and take what info i need into my observable collection, so there is no direct connection back to the database, maybe this is why the itemsourcechanged does not fire?

dataGrid6.ItemsSourceChanged += dataGrid6_ItemsSourceChanged;

dataGrid6.Model.View.RecordPropertyChanged += View_RecordPropertyChanged;

i my case both these fail to fire hence i used the EditCellComplete to catch the price change from say 10.00 to 12.00 but still the tablesummary update does not work.

also my observable collection does not have a NotifiationObject, may this also i need to change?

public class Chemical_Data

{

public string wellID { set; get; }

public string name { set; get; }

public string function { set; get; }

public double price { set; get; }

public double price2 { set; get; }

//public double stock { set; get; }

public double usedInt { set; get; }

public double usedWell { set; get; }

public double costInt { set; get; }

public double costWell { set; get; }

public double costWell2 { set; get; }

//public double conc { set; get; }

public DataTable dtIntDetails { set; get; }

}

public class Chemical : ObservableCollection<Chemical_Data>

{

public Chemical()

{

Chemical_Data chemical = new Chemical_Data();

}

}


Regards
Bruce

Jai Ganesh S [Syncfusion]
Replied On August 19, 2016 12:42 PM UTC

Hi Bruce, 
 
You can achieve your requirement to update the GroupSummaries at runtime by using the below code, 
 
this.dataGrid.ItemsSourceChanged += dataGrid_ItemsSourceChanged; 
 
void dataGrid_ItemsSourceChanged(object sender, Syncfusion.Windows.ComponentModel.SyncfusionRoutedEventArgs args) 
{ 
    this.dataGrid.Model.View.RecordPropertyChanged += View_RecordPropertyChanged; 
} 
 
void View_RecordPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) 
{ 
    var recordentry = this.dataGrid.Model.View.Records.GetRecord(sender); 
    if(recordentry.Parent is Group) 
        this.dataGrid.Model.View.TopLevelGroup.UpdateSummaries(recordentry.Parent as Group); 
} 
  
Regards, 
Jai Ganesh S 


Bruce Guthrie
Replied On August 19, 2016 01:31 PM UTC

Jai

sorry i still cannot ge this to work, i think the main issue is that the this.dataGrid.ItemsSourceChanged += dataGrid_ItemsSourceChanged is not firing in my example.  so i cannot get the correct use of the this.dataGrid.Model.View.RecordPropertyChanged += View_RecordPropertyChanged Event.

i have to use the EditCellCompleted event and the updating does not work in my case in fact the

    var recordentry = this.dataGrid.Model.View.Records.GetRecord(sender); returns null as i have to put it in the Edit cell completed function.


private void dataGrid6_CurrentCellEditingComplete(object sender, Syncfusion.Windows.ComponentModel.SyncfusionRoutedEventArgs arg




{



var recordentry = this.dataGrid6.Model.View.Records.GetRecord(sender);   ----- in my example this returns null........ sender is a GridDataControl


if (recordentry.Parent is Group)


this.dataGrid6.Model.View.TopLevelGroup.UpdateSummaries(recordentry.Parent as Group);


maybe i need to change my observablecollection but i do not what to change it with to allow the capture of the ItemSourceChanged Event.



Regards

Bruce




Jai Ganesh S [Syncfusion]
Replied On August 22, 2016 12:15 PM UTC

Hi Bruce, 
 
Sorry for the inconvenience. We have modified the code for calling the RecordPropertyChanged event in Loaded and ItemsSourceChanged event like below, 
  
this.dataGrid.ItemsSourceChanged += dataGrid_ItemsSourceChanged; 
this.Loaded += MainWindow_Loaded; 
 
void MainWindow_Loaded(object sender, RoutedEventArgs e) 
{ 
    if (!iseventwired && this.dataGrid.Model.View != null) 
    { 
        this.dataGrid.Model.View.RecordPropertyChanged += View_RecordPropertyChanged; 
        iseventwired = true; 
    } 
} 
 
bool iseventwired = false; 
void dataGrid_ItemsSourceChanged(object sender, Syncfusion.Windows.ComponentModel.SyncfusionRoutedEventArgs args) 
{ 
    if (!iseventwired && this.dataGrid.Model.View != null) 
    { 
        this.dataGrid.Model.View.RecordPropertyChanged += View_RecordPropertyChanged; 
        iseventwired = true; 
    } 
} 
 
void View_RecordPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) 
{ 
    //Here sender is underlying data object. 
    var recordentry = this.dataGrid.Model.View.Records.GetRecord(sender); 
    if (recordentry != null && recordentry.Parent is Group) 
    { 
        this.dataGrid.Model.View.TopLevelGroup.UpdateSummaries(recordentry.Parent as Group); 
    } 
} 
 
 
 
Regards, 
Jai Ganesh S 
 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;