Conditional Summaries
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.
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.
SIGN IN To post a reply.
16 Replies
AD
Administrator
Syncfusion Team
October 20, 2006 01:22 PM UTC
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
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
AD
Administrator
Syncfusion Team
November 1, 2006 03:36 PM UTC
How would I go about binding this new summary to a text box?
AD
Administrator
Syncfusion Team
November 2, 2006 12:12 PM UTC
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
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
AD
Administrator
Syncfusion Team
November 2, 2006 07:45 PM UTC
this appears to be setting the value of the summary cell, not the text box.
AD
Administrator
Syncfusion Team
November 3, 2006 05:40 PM UTC
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
AD
Administrator
Syncfusion Team
November 14, 2006 05:45 PM UTC
Any answers for this?
AD
Administrator
Syncfusion Team
November 15, 2006 09:07 AM UTC
Hi Paulo,
We will work out for a solution and let you know the details soon. Thanks for being patience.
Best regards,
Haneef
We will work out for a solution and let you know the details soon. Thanks for being patience.
Best regards,
Haneef
AD
Administrator
Syncfusion Team
November 16, 2006 09:18 AM UTC
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
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
AD
Administrator
Syncfusion Team
November 16, 2006 05:27 PM UTC
This only works if the row is visible. Which is not what I want because I want to hide the summary row.
AD
Administrator
Syncfusion Team
November 24, 2006 07:04 AM UTC
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
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
AD
Administrator
Syncfusion Team
November 27, 2006 06:10 PM UTC
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.
AD
Administrator
Syncfusion Team
November 28, 2006 12:31 PM UTC
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
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
AD
Administrator
Syncfusion Team
November 28, 2006 05:14 PM UTC
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
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
AD
Administrator
Syncfusion Team
November 29, 2006 04:33 AM UTC
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
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
AD
Administrator
Syncfusion Team
November 29, 2006 06:52 PM UTC
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
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
AD
Administrator
Syncfusion Team
November 29, 2006 06:56 PM UTC
Here's the right attachment, the other one I attached didn't work how i wanted it to.
ggcsummary0.zip
ggcsummary0.zip
SIGN IN To post a reply.
- 16 Replies
- 2 Participants
-
PC Paulo Cristini
- Oct 13, 2006 10:55 PM UTC
- Nov 29, 2006 06:56 PM UTC