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.

Conditional Summaries

Thread ID:

Created:

Updated:

Platform:

Replies:

50556 Oct 13,2006 06:55 PM Nov 29,2006 01:56 PM Windows Forms 16
loading
Tags: Grouping
Paulo Cristini
Asked On October 13, 2006 06:55 PM

Is it possible to do summaries based on certain circumstances?

Say I have two columns
Total | State

and the state is selectable through a combo box within the cell on the row.

What I''d like to do is have a running total but only for say state "Review".

I''d prefer to do this due to the grid''s summary engine is probably more efficient then me going through each record and totalling it up everytime a record is changed.

Administrator [Syncfusion]
Replied On October 20, 2006 09:22 AM

There are a couple of ways you can tackle this problem. One is to use an unbound column and to conditionally make the value of this unbound column either be the value you want to add or 0 depending upon the test value from the record. But this requires another visible column in your grid.

To avoid the extra visible column, you can use a custom summarytype. Here is a little sample that sums up the values if column 3 provided the value in column 1 is 2 using a custom summary.
http://www.syncfusion.com/Support/user/uploads/GGCSummary3_3bd340.zip

Administrator [Syncfusion]
Replied On November 1, 2006 10:36 AM

How would I go about binding this new summary to a text box?

Administrator [Syncfusion]
Replied On November 2, 2006 07:12 AM

Hi Paulo,

You can handle the QueryCellFormattedText event to set the value of the textbox to the SummaryCell in a grid. Here is a code snippet

private void gridGroupingControl1_QueryCellFormattedText(object sender, Syncfusion.Windows.Forms.Grid.GridCellTextEventArgs e)
{
GridTableCellStyleInfo info = e.Style as GridTableCellStyleInfo;
if(info.TableCellIdentity.TableCellType == GridTableCellType.SummaryFieldCell)
{
double v;
e.Handled = true;
if( this.textBox1.Focused
&& this.textBox1.Text != string.Empty
&& double.TryParse(this.textBox1.Text,System.Globalization.NumberStyles.Any,Application.CurrentCulture,out v))
{
e.Text = this.textBox1.Text ;
}
else if( e.Value != null )
{
e.Text = e.Value.ToString();
this.textBox1.Text = e.Value.ToString();
}
}
}

private void textBox1_TextChanged(object sender, System.EventArgs e)
{ this.gridGroupingControl1.Refresh(); }

Best Regards,
Haneef

Administrator [Syncfusion]
Replied On November 2, 2006 02:45 PM

this appears to be setting the value of the summary cell, not the text box.

Administrator [Syncfusion]
Replied On November 3, 2006 12:40 PM

What I'd like to be able to do is to use the TextBox's DataBindings to be able to have the text within it updated automatically when the value of the summary changes. But I'm not sure where to retrieve an appropriate value to pass in as the datasource to the text box's binding object

Administrator [Syncfusion]
Replied On November 14, 2006 12:45 PM

Any answers for this?

Administrator [Syncfusion]
Replied On November 15, 2006 04:07 AM

Hi Paulo,

We will work out for a solution and let you know the details soon. Thanks for being patience.

Best regards,
Haneef

Administrator [Syncfusion]
Replied On November 16, 2006 04:18 AM

Hi Paulo,

Our apologies for the delay in response.

One way you can do this is to handle a QueryCellStyleInfo event on the grid and use the control cell type to set the textbox in a grid's summary field cell. Andalso you can handle the TextChanged event of the textbox to bind the summary field cell textbox and textbox. Here is a modified sample to show this.

http://www.syncfusion.com/Support/user/uploads/GGCSummary3_f19cec74.zip

Best Regards,
Haneef

Administrator [Syncfusion]
Replied On November 16, 2006 12:27 PM

This only works if the row is visible. Which is not what I want because I want to hide the summary row.

Administrator [Syncfusion]
Replied On November 24, 2006 02:04 AM

Hi Paulo,

Thanks for your patience.

Please try the attached sample that is working fine, let me know if you are looking something different.
GGCSummarytoTextBoxBindingSample

Best Regards,
Haneef

Administrator [Syncfusion]
Replied On November 27, 2006 01:10 PM

Again, this only works when the new record is added because the focus of the record goes to the bottom of the screen (where the summary record resides). If the summary record is off the screen and you edit one of the cells, the total does not update.


Administrator [Syncfusion]
Replied On November 28, 2006 07:31 AM

Hi Paulo,

You can handle the TableControlCurrentCellAcceptedChanges event and call the refresh method to update the summary cell in a grid. Please try the sample and let me know if this helps.

private void gridGroupingControl1_TableControlCurrentCellAcceptedChanges(object sender, Syncfusion.Windows.Forms.Grid.Grouping.GridTableControlCancelEventArgs e)
{e.TableControl.Table.SummariesDirty = true;}

Sample : ModifiedSummaryTextBox.zip

Best Regards,
Haneef

Administrator [Syncfusion]
Replied On November 28, 2006 12:14 PM

Haneef,
As said before this won't work if using QueryCellStyleInfo because the event is only fired when the summary cell is visible on the screen. I've attached an example showing this.

When you run the app, change one of the first few rows. The summary will not update. Now scroll to the bottom of the grid and the summary will update because QueryCellStyleInfo will be triggered when the row becomes visible.

summary2.zip

Administrator [Syncfusion]
Replied On November 28, 2006 11:33 PM

Hi Paulo,

I regret for the inconvenience caused.

You can handle the TableControlCurrentCellAcceptedChanges event and use the Table.GetSummaries() method to get all updated summaries in a GridTable. Here is a code snippet to show this.

private void gridGroupingControl1_TableControlCurrentCellAcceptedChanges(object sender, GridTableControlCancelEventArgs e)
{
SummaryDescriptorCollection sdc = this.gridGroupingControl1.TableDescriptor.Summaries;
ISummary[] summaries = this.gridGroupingControl1.Table.GetSummaries();
int index = sdc.IndexOf(sdc["Row 0Col2"]);
Int32AggregateSummary summary = summaries[index] as Int32AggregateSummary;
summary = summaries[index] as Int32AggregateSummary;
this.TextBox1.Text = summary.Sum.ToString();
}

Here is a modified sample.
Modifiedsummary2.zip

Thanks for your patience.

Best Regards,
Haneef

Administrator [Syncfusion]
Replied On November 29, 2006 01:52 PM

Haneef,

We're gettting closer. This works for the most part. Only part that is missing is when a new record is added.

Attached is a modified version of your solution that has a few of the issues I noticed fixed.

The problem I'm seeing now is when a new record is added the summary doesn't take into account the newly added value.

I'm setting the text of the text box in the GroupSummaryInvalidated event, but this only appears to take the value of the summary BEFORE the newly added value...

Is there any event I can capture that indicates when the recalculating of the summary has completed?

ggcsummary.zip

Administrator [Syncfusion]
Replied On November 29, 2006 01:56 PM

Here's the right attachment, the other one I attached didn't work how i wanted it to.

ggcsummary0.zip

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.

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.

;