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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Getting values from summary rows

Thread ID:

Created:

Updated:

Platform:

Replies:

24926 Feb 14,2005 06:25 PM UTC Jun 21,2005 08:17 PM UTC WinForms 13
loading
Tags: Grouping
Anthony Avella
Asked On February 14, 2005 06:25 PM UTC

Executing the following loop- foreach(Element theElement in grid.Table.DisplayElements) - gives me each summary row if my grid is group and not expanded. While working with the theElement variable, how can I retrieve the values in each summary cell of that element? Thanks

Administrator [Syncfusion]
Replied On February 15, 2005 06:38 PM UTC

Anthony, To get actual summaries (the ones that are calculated) you can get the ParentGroup and go from there. Example: Group group = el.ParentGroup; GridTable table = (GridTable) el.ParentTable; GridSummaryRowDescriptor summaryRowDescriptor = table.TableDescriptor.SummaryRows["SummaryRow 1"]; GridSummaryColumnDescriptor sumCol1 = summaryRowDescriptor.SummaryColumns["FreightAverage"]; if (sumCol1 != null) { SummaryDescriptor sd1 = sumCol1.SummaryDescriptor; if (sd1 != null) { int indexOfSd1 = table.TableDescriptor.Summaries.IndexOf(sd1); ISummary sum1 = el.ParentGroup.GetSummaries(table)[indexOfSd1]; string text1 = sumCol1.GetDisplayText(sum1); e.Style.Text = text1; // - or - (access value directly) // strong typed - you have to cast to Int32AggregateSummary. DoubleAggregateSummary summary1 = (DoubleAggregateSummary) el.ParentGroup.GetSummaries(table)[indexOfSd1]; e.Style.Text = string.Format("{0:c}", summary1.Average); } } To get the edited summaries you also should get the ParentGroup and then check the Hashtable (or whatever storage you implemented for editable summaries) and look up the value there. Stefan >Executing the following loop- foreach(Element theElement in grid.Table.DisplayElements) - gives me each summary row if my grid is group and not expanded. > >While working with the theElement variable, how can I retrieve the values in each summary cell of that element? > >Thanks

Anthony Avella
Replied On February 16, 2005 05:54 PM UTC

I''m getting an error for ISummary (type or namespace could not be found). What is this and what namespace (using directive) do I need to use? Also, is there a way to avoid using the hard coded summary names you use ("SummaryRow1" and "FreightAverage") and loop through the Element''s summary rows and each row''s columns? Lastly, how can I access the detail records of the display element if the element is a custom caption row? Thanks >Anthony, > > >To get actual summaries (the ones that are calculated) you can get the ParentGroup and go from there. > >Example: > > >Group group = el.ParentGroup; > > GridTable table = (GridTable) el.ParentTable; > GridSummaryRowDescriptor summaryRowDescriptor = table.TableDescriptor.SummaryRows["SummaryRow 1"]; > GridSummaryColumnDescriptor sumCol1 = summaryRowDescriptor.SummaryColumns["FreightAverage"]; > > if (sumCol1 != null) > { > SummaryDescriptor sd1 = sumCol1.SummaryDescriptor; > if (sd1 != null) > { > int indexOfSd1 = table.TableDescriptor.Summaries.IndexOf(sd1); > > ISummary sum1 = el.ParentGroup.GetSummaries(table)[indexOfSd1]; > string text1 = sumCol1.GetDisplayText(sum1); > e.Style.Text = text1; > > // - or - (access value directly) > // strong typed - you have to cast to Int32AggregateSummary. > > DoubleAggregateSummary summary1 = (DoubleAggregateSummary) el.ParentGroup.GetSummaries(table)[indexOfSd1]; > e.Style.Text = string.Format("{0:c}", summary1.Average); > } > } > >To get the edited summaries you also should get the ParentGroup and then check the Hashtable (or whatever storage you implemented for editable summaries) and look up the value there. > >Stefan > >>Executing the following loop- foreach(Element theElement in grid.Table.DisplayElements) - gives me each summary row if my grid is group and not expanded. >> >>While working with the theElement variable, how can I retrieve the values in each summary cell of that element? >> >>Thanks

Administrator [Syncfusion]
Replied On February 16, 2005 09:36 PM UTC

Anthony, use this line at beginning of your file. using ISummary = Syncfusion.Collections.BinaryTree.ITreeTableSummary; ITreeTableSummary is the interface that each summary element implements, e.g. check out DoubleAggregateSummary summary class. Instead of GridSummaryRowDescriptor summaryRowDescriptor = table.TableDescriptor.SummaryRows["SummaryRow 1"]; GridSummaryColumnDescriptor sumCol1 = summaryRowDescriptor.SummaryColumns["FreightAverage"]; you can do this loop: foreach (GridSummaryRowDescriptor summaryRowDescriptor = table.TableDescriptor.SummaryRows) { foreach (GridSummaryColumnDescriptor sumCol1 in summaryRowDescriptor.SummaryColumns) { .... } } if the element is a custom caption row you can access the detail records as follows: Group parentGroup = el.ParentGroup; foreach (Record r in parentGroup.FlattenedFilteredRecords) { ... } Stefan >I''m getting an error for ISummary (type or namespace could not be found). >What is this and what namespace (using directive) do I need to use? > >Also, is there a way to avoid using the hard coded summary names you use ("SummaryRow1" and "FreightAverage") and loop through the Element''s summary rows and each row''s columns? > >Lastly, how can I access the detail records of the display element if the element is a custom caption row? > >Thanks > >>Anthony, >> >> >>To get actual summaries (the ones that are calculated) you can get the ParentGroup and go from there. >> >>Example: >> >> >>Group group = el.ParentGroup; >> >> GridTable table = (GridTable) el.ParentTable; >> GridSummaryRowDescriptor summaryRowDescriptor = table.TableDescriptor.SummaryRows["SummaryRow 1"]; >> GridSummaryColumnDescriptor sumCol1 = summaryRowDescriptor.SummaryColumns["FreightAverage"]; >> >> if (sumCol1 != null) >> { >> SummaryDescriptor sd1 = sumCol1.SummaryDescriptor; >> if (sd1 != null) >> { >> int indexOfSd1 = table.TableDescriptor.Summaries.IndexOf(sd1); >> >> ISummary sum1 = el.ParentGroup.GetSummaries(table)[indexOfSd1]; >> string text1 = sumCol1.GetDisplayText(sum1); >> e.Style.Text = text1; >> >> // - or - (access value directly) >> // strong typed - you have to cast to Int32AggregateSummary. >> >> DoubleAggregateSummary summary1 = (DoubleAggregateSummary) el.ParentGroup.GetSummaries(table)[indexOfSd1]; >> e.Style.Text = string.Format("{0:c}", summary1.Average); >> } >> } >> >>To get the edited summaries you also should get the ParentGroup and then check the Hashtable (or whatever storage you implemented for editable summaries) and look up the value there. >> >>Stefan >> >>>Executing the following loop- foreach(Element theElement in grid.Table.DisplayElements) - gives me each summary row if my grid is group and not expanded. >>> >>>While working with the theElement variable, how can I retrieve the values in each summary cell of that element? >>> >>>Thanks

Anthony Avella
Replied On February 17, 2005 04:44 PM UTC

This method gets away from iterating through/accessing the DisplayElements of the grid. How can I get the Element of the current GridSummaryRowDescriptor or the current GridSummaryColumnDescriptor I''m iterating through in their respective foreach loops? Or, is there a way to cast one of these to an Element (my attempts so far have been futile)? Thanks. >Anthony, > >use this line at beginning of your file. > >using ISummary = Syncfusion.Collections.BinaryTree.ITreeTableSummary; > > >ITreeTableSummary is the interface that each summary element implements, e.g. check out DoubleAggregateSummary summary class. > > >Instead of >GridSummaryRowDescriptor summaryRowDescriptor = table.TableDescriptor.SummaryRows["SummaryRow 1"]; >GridSummaryColumnDescriptor sumCol1 = summaryRowDescriptor.SummaryColumns["FreightAverage"]; > >you can do this loop: > >foreach (GridSummaryRowDescriptor summaryRowDescriptor = table.TableDescriptor.SummaryRows) >{ >foreach (GridSummaryColumnDescriptor sumCol1 in summaryRowDescriptor.SummaryColumns) >{ >.... >} >} > > >if the element is a custom caption row you can access the detail records as follows: > >Group parentGroup = el.ParentGroup; > >foreach (Record r in parentGroup.FlattenedFilteredRecords) >{ >... >} > > >Stefan > > >>I''m getting an error for ISummary (type or namespace could not be found). >>What is this and what namespace (using directive) do I need to use? >> >>Also, is there a way to avoid using the hard coded summary names you use ("SummaryRow1" and "FreightAverage") and loop through the Element''s summary rows and each row''s columns? >> >>Lastly, how can I access the detail records of the display element if the element is a custom caption row? >> >>Thanks >> >>>Anthony, >>> >>> >>>To get actual summaries (the ones that are calculated) you can get the ParentGroup and go from there. >>> >>>Example: >>> >>> >>>Group group = el.ParentGroup; >>> >>> GridTable table = (GridTable) el.ParentTable; >>> GridSummaryRowDescriptor summaryRowDescriptor = table.TableDescriptor.SummaryRows["SummaryRow 1"]; >>> GridSummaryColumnDescriptor sumCol1 = summaryRowDescriptor.SummaryColumns["FreightAverage"]; >>> >>> if (sumCol1 != null) >>> { >>> SummaryDescriptor sd1 = sumCol1.SummaryDescriptor; >>> if (sd1 != null) >>> { >>> int indexOfSd1 = table.TableDescriptor.Summaries.IndexOf(sd1); >>> >>> ISummary sum1 = el.ParentGroup.GetSummaries(table)[indexOfSd1]; >>> string text1 = sumCol1.GetDisplayText(sum1); >>> e.Style.Text = text1; >>> >>> // - or - (access value directly) >>> // strong typed - you have to cast to Int32AggregateSummary. >>> >>> DoubleAggregateSummary summary1 = (DoubleAggregateSummary) el.ParentGroup.GetSummaries(table)[indexOfSd1]; >>> e.Style.Text = string.Format("{0:c}", summary1.Average); >>> } >>> } >>> >>>To get the edited summaries you also should get the ParentGroup and then check the Hashtable (or whatever storage you implemented for editable summaries) and look up the value there. >>> >>>Stefan >>> >>>>Executing the following loop- foreach(Element theElement in grid.Table.DisplayElements) - gives me each summary row if my grid is group and not expanded. >>>> >>>>While working with the theElement variable, how can I retrieve the values in each summary cell of that element? >>>> >>>>Thanks

Anthony Avella
Replied On February 17, 2005 05:27 PM UTC

Also.... The second signature for the sumCol.GetDisplayText( function looks for the table of the grid and a GridSummaryRow variable. How can I cast a GridSummaryRowDescriptor to a GridSummaryRow? Thanks >Anthony, > >use this line at beginning of your file. > >using ISummary = Syncfusion.Collections.BinaryTree.ITreeTableSummary; > > >ITreeTableSummary is the interface that each summary element implements, e.g. check out DoubleAggregateSummary summary class. > > >Instead of >GridSummaryRowDescriptor summaryRowDescriptor = table.TableDescriptor.SummaryRows["SummaryRow 1"]; >GridSummaryColumnDescriptor sumCol1 = summaryRowDescriptor.SummaryColumns["FreightAverage"]; > >you can do this loop: > >foreach (GridSummaryRowDescriptor summaryRowDescriptor = table.TableDescriptor.SummaryRows) >{ >foreach (GridSummaryColumnDescriptor sumCol1 in summaryRowDescriptor.SummaryColumns) >{ >.... >} >} > > >if the element is a custom caption row you can access the detail records as follows: > >Group parentGroup = el.ParentGroup; > >foreach (Record r in parentGroup.FlattenedFilteredRecords) >{ >... >} > > >Stefan > > >>I''m getting an error for ISummary (type or namespace could not be found). >>What is this and what namespace (using directive) do I need to use? >> >>Also, is there a way to avoid using the hard coded summary names you use ("SummaryRow1" and "FreightAverage") and loop through the Element''s summary rows and each row''s columns? >> >>Lastly, how can I access the detail records of the display element if the element is a custom caption row? >> >>Thanks >> >>>Anthony, >>> >>> >>>To get actual summaries (the ones that are calculated) you can get the ParentGroup and go from there. >>> >>>Example: >>> >>> >>>Group group = el.ParentGroup; >>> >>> GridTable table = (GridTable) el.ParentTable; >>> GridSummaryRowDescriptor summaryRowDescriptor = table.TableDescriptor.SummaryRows["SummaryRow 1"]; >>> GridSummaryColumnDescriptor sumCol1 = summaryRowDescriptor.SummaryColumns["FreightAverage"]; >>> >>> if (sumCol1 != null) >>> { >>> SummaryDescriptor sd1 = sumCol1.SummaryDescriptor; >>> if (sd1 != null) >>> { >>> int indexOfSd1 = table.TableDescriptor.Summaries.IndexOf(sd1); >>> >>> ISummary sum1 = el.ParentGroup.GetSummaries(table)[indexOfSd1]; >>> string text1 = sumCol1.GetDisplayText(sum1); >>> e.Style.Text = text1; >>> >>> // - or - (access value directly) >>> // strong typed - you have to cast to Int32AggregateSummary. >>> >>> DoubleAggregateSummary summary1 = (DoubleAggregateSummary) el.ParentGroup.GetSummaries(table)[indexOfSd1]; >>> e.Style.Text = string.Format("{0:c}", summary1.Average); >>> } >>> } >>> >>>To get the edited summaries you also should get the ParentGroup and then check the Hashtable (or whatever storage you implemented for editable summaries) and look up the value there. >>> >>>Stefan >>> >>>>Executing the following loop- foreach(Element theElement in grid.Table.DisplayElements) - gives me each summary row if my grid is group and not expanded. >>>> >>>>While working with the theElement variable, how can I retrieve the values in each summary cell of that element? >>>> >>>>Thanks

Administrator [Syncfusion]
Replied On February 21, 2005 08:45 AM UTC

Anthony, >>> Q: This method gets away from iterating through/accessing the DisplayElements of the grid. How can I get the Element of the current GridSummaryRowDescriptor or the current GridSummaryColumnDescriptor I''''m iterating through in their respective foreach loops? Or, is there a way to cast one of these to an Element (my attempts so far have been futile)? <<<< If you are on a caption row and the Show Summaries in Captions is enabled then the summary row descriptor is: if (el is CaptionRow) { IGridGroupOptionsSource go = el.ParentGroup as IGridGroupOptionsSource; string captionSummaryRow = table.TableDescriptor.SummaryRows[go.GroupOptions.CaptionSummaryRow]; // The GridGroupOptionsStyleInfo.CaptionSummaryRow Property specifies a summary row that should be displayed inside CaptionSummaryCells when ShowCaptionSummaryCells has been set to true. GridSummaryRowDescriptor summaryRowDescriptor = table.TableDescriptor.SummaryRows[captionSummaryRow]; } If you are iterating through regular GridSummaryRows you can do this: GridSummaryRow sr = el as GridSummaryRow; if (sr != null) { GridSummaryRowDescriptor summaryRowDescriptor = sr.SummaryRowDescriptor; } >>>> Q: The second signature for the sumCol.GetDisplayText( function looks for the table of the grid and a GridSummaryRow variable. <<<< Ok, we added more overloads with later versions to make it easier. This one should work also with earlier versions: GridSummaryRow sr = el as GridSummaryRow; if (sr != null) { GridSummaryRowDescriptor summaryRowDescriptor = sr.SummaryRowDescriptor; string text = sumCol1.GetDisplayText(sr.ParentTable, sr); } Stefan

Anthony Avella
Replied On June 16, 2005 06:46 PM UTC

Hi Stefan. This project hs gained priority for me again. I have a number of issues with this problem. 1- The following code doesn''t seem to work for me: intSumColIndex = grid.Table.TableDescriptor.Summaries.IndexOf(sumCol.Name); Syncfusion.Collections.BinaryTree.ITreeTableSummary ISCurrentColumn = theElement.ParentGroup.GetSummaries(grid.Table)[intSumColIndex + 1]; strSummaryColumnValue = sumCol.GetDisplayText(ISCurrentColumn); intSumColIndex always turns out to be -1. 2- I tried using this code you gave me to use instead: GridSummaryRow sr = el as GridSummaryRow; if (sr != null) { GridSummaryRowDescriptor summaryRowDescriptor = sr.SummaryRowDescriptor; string text = sumCol1.GetDisplayText(sr.ParentTable, sr); } and sr always = null In the end, I''m trying to export exactly what''s on the grid to an excel spreadsheet (we''re using version 3.0.1.0 of the grid). Can you help me with that? Thanks.

Administrator [Syncfusion]
Replied On June 17, 2005 02:59 PM UTC

Hi Anthony, GridSummaryRow sr = el as GridSummaryRow; will return null if el is not a summary row. You can do a Console.Writeline(el.GetType().ToString()); to determine the type of the element. If it is a caption row look at the code snippets earlier in this thread where it shows how to get summary information for a caption row. Stefan >Hi Stefan. >This project hs gained priority for me again. >I have a number of issues with this problem. > >1- The following code doesn''t seem to work for me: >intSumColIndex = grid.Table.TableDescriptor.Summaries.IndexOf(sumCol.Name); > > Syncfusion.Collections.BinaryTree.ITreeTableSummary ISCurrentColumn = theElement.ParentGroup.GetSummaries(grid.Table)[intSumColIndex + 1]; > strSummaryColumnValue = sumCol.GetDisplayText(ISCurrentColumn); > >intSumColIndex always turns out to be -1. > >2- I tried using this code you gave me to use instead: > >GridSummaryRow sr = el as GridSummaryRow; >if (sr != null) >{ >GridSummaryRowDescriptor summaryRowDescriptor = sr.SummaryRowDescriptor; >string text = sumCol1.GetDisplayText(sr.ParentTable, sr); >} > >and sr always = null > >In the end, I''m trying to export exactly what''s on the grid to an excel spreadsheet (we''re using version 3.0.1.0 of the grid). > >Can you help me with that? > >Thanks.

Anthony Avella
Replied On June 17, 2005 03:46 PM UTC

I use custom caption rows. How do I turn those into GridSummaryRows?

Administrator [Syncfusion]
Replied On June 17, 2005 09:08 PM UTC

Use the following code: if (el is CaptionRow) { IGridGroupOptionsSource go = el.ParentGroup as IGridGroupOptionsSource; string captionSummaryRow = table.TableDescriptor.SummaryRows[go.GroupOptions.CaptionSummaryRow]; // The GridGroupOptionsStyleInfo.CaptionSummaryRow Property specifies a summary row that should be displayed inside CaptionSummaryCells when ShowCaptionSummaryCells has been set to true. GridSummaryRowDescriptor summaryRowDescriptor = table.TableDescriptor.SummaryRows[captionSummaryRow]; } Stefan >I use custom caption rows. >How do I turn those into GridSummaryRows?

Anthony Avella
Replied On June 20, 2005 05:01 PM UTC

Hi. I already have this code from you. This still does not get me to a GridSummaryRow. I need to be able to execute this line of code, where sr is a GridSummaryRow. string text = sumCol.GetDisplayText(sr.ParentTable, sr);

Administrator [Syncfusion]
Replied On June 21, 2005 04:24 AM UTC

Anthony, you can''t convert a GridCaptionRow into a GridSummaryRow, but you can get the GridSummaryRowDescriptor that has been assigned to CaptionRows by GridGroupOptionsStyleInfo.CaptionSummaryRow. in the above code, once this line of code executes, you do have a summaryRowDescriptor: GridSummaryRowDescriptor summaryRowDescriptor = table.TableDescriptor.SummaryRows[captionSummaryRow]; After that line of code insert the following code: GridSummaryColumnDescriptor sumCol1 = summaryRowDescriptor.SummaryColumns["FreightAverage"]; ISummary summary1 = sumCol1.GetSummary(el.ParentTable, el); string text = sumCol1.GetDisplayText(summary1); Instead of hard-coding FreightAverage, you can also loop through the columns with the following loop: foreach (GridSummaryColumnDescriptor sumCol1 in summaryRowDescriptor.SummaryColumns) { .... } Complete code for looping through summaryColumns within a CaptionRow looks like this: if (el is CaptionRow) { IGridGroupOptionsSource go = el.ParentGroup as IGridGroupOptionsSource; string captionSummaryRow = table.TableDescriptor.SummaryRows[go.GroupOptions.CaptionSummaryRow]; // The GridGroupOptionsStyleInfo.CaptionSummaryRow Property specifies a summary row that should be displayed inside CaptionSummaryCells when ShowCaptionSummaryCells has been set to true. GridSummaryRowDescriptor summaryRowDescriptor = table.TableDescriptor.SummaryRows[captionSummaryRow]; foreach (GridSummaryColumnDescriptor sumCol1 in summaryRowDescriptor.SummaryColumns) { ISummary summary1 = sumCol1.GetSummary(el.ParentTable, el); string text = sumCol1.GetDisplayText(summary1); } } Alternatively, you could also modify the code you gave earlier: Instead of intSumColIndex = grid.Table.TableDescriptor.Summaries.IndexOf(sumCol.Name); you should write: intSumColIndex = grid.Table.TableDescriptor.Summaries.IndexOf(sumCol.GetSummaryDescriptorName()); - or - intSumColIndex = sumCol.GetSummaryIndex(); Then intSumColIndex should not be -1 any more. Stefan

Anthony Avella
Replied On June 21, 2005 08:17 PM UTC

This worked great. Thanks.

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

;