This is a migrated thread and some comments may be shown as answers.

summary cell value

5 Answers 390 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Sadly Stripy
Top achievements
Rank 1
Sadly Stripy asked on 25 Jun 2011, 09:07 PM
Hi to all,
I have problem to use value from cell in summary row.

On my winform I have two radgridviews with their summary rows. How can I use that values to calculate their sum and show that result in some radlabel?

RadLabel1.Text = sum of column "days" on RadGridView1+ sum of column "items" on RadGridView2



Thanks,
sadly stripy

5 Answers, 1 is accepted

Sort by
0
Alexander
Telerik team
answered on 29 Jun 2011, 01:27 PM
Hello Sadly,

RadGridView does not provide direct API for getting the values of a summary row, but you can use any of the following approaches to achieve this:

1. Re-evaluate the summary item and get the result value:
GridViewSummaryRowItem summaryRowItem = this.radGridView1.SummaryRowsTop[0];
GridViewSummaryItem summaryItem = summaryRowItem["ColumnName"][0];
object summary = summaryItem.Evaluate(this.radGridView1.MasterTemplate);

2. Use the GroupSummaryEvaluate event of RadGridView to get the value of a summary item:
private object summary;
private void radGridView1_GroupSummaryEvaluate(object sender, GroupSummaryEvaluationEventArgs e)
{
    this.summary = e.Value;
}

I hope it helps you to achieve your scenario. Please note that we are still expecting an answer from you on the questions asked in your thread "element hierarchy editor problem". This will allow us to continue supporting your enquiries.

Best regards,
Alexander
the Telerik team
Q1’11 SP1 of RadControls for WinForms is available for download; also available is the Q2'11 Roadmap for Telerik Windows Forms controls.
0
Javier Gonzalez de Aragon
Top achievements
Rank 2
answered on 27 Dec 2011, 02:03 AM
Hi, I'm trying your recommendation to re-evaluate the summary item and get the result value but I'm having problems. I have summary rows on two hierarchical subgrids, not on the master template.

My code is as follows:

Dim CostoD As Decimal = 0
Dim CostoI As Decimal = 0
 
Dim summaryRowItem As GridViewSummaryRowItem = gvProduccionDetalle.Templates(0).SummaryRowsTop(0)
Dim summaryItem As GridViewSummaryItem = summaryRowItem("CostoMP")(0)
CostoD += summaryItem.Evaluate(gvProduccionDetalle.Templates(0))

I receive an ArgumentOutOfRangeException when I use the Evaluate method.

Any ideas?

Thanks,

Javier
0
Svett
Telerik team
answered on 29 Dec 2011, 03:28 PM
Hi Javier,

Thank you for writing.

If you want to evaluate the summary for all rows from second level in hierarchy you should use the following code snippet:
Dim summaryRowItem As GridViewSummaryRowItem = Me.radGridView1.Templates(0).SummaryRowsTop(0)
Dim expression As String = summaryRowItem(0).GetSummaryExpression()
Dim value As Object = Me.radGridView1.Templates(0).DataView.Evaluate(expression, Me.radGridView1.Templates(0).Rows)

I hope that you find this information useful. Should you have any other questions, do not hesitate to contact us.

All the best,
Svett
the Telerik teamQ3’11 of RadControls for WinForms is available for download (see what's new). Get it today.
0
Javier Gonzalez de Aragon
Top achievements
Rank 2
answered on 05 Jan 2012, 03:04 AM
Thanks, that worked great. I have an other question. The previous code evaluated all of the summary items for all of the rows on the gridview. How can I get the total of each row at a time?

Thanks again,

Javier
0
Svett
Telerik team
answered on 06 Jan 2012, 05:07 PM
Hello Javier,

If you want to evaluate the summary items of the child rows of a particular row in hierarchy, you can use the following code snippet:

GridViewHierarchyRowInfo hierarchyRow = this.radGridView1.MasterTemplate.ChildRows[0] as GridViewHierarchyRowInfo;
GridViewSummaryRowItem summaryRowItem = this.radGridView1.Templates[0].SummaryRowsTop[0];
string expression = summaryRowItem[0].GetSummaryExpression();
object value = this.radGridView1.Templates[0].DataView.Evaluate(expression, hierarchyRow.ChildRows);
Greetings,
Svett
the Telerik team

SP1
of Q3’11 of RadControls for WinForms is available for download (see what's new).
Tags
GridView
Asked by
Sadly Stripy
Top achievements
Rank 1
Answers by
Alexander
Telerik team
Javier Gonzalez de Aragon
Top achievements
Rank 2
Svett
Telerik team
Share this question
or