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. Image for the cookie policy date

Showing a repeating string value in a summary column

Please look at the below code for the creation of a summary column: gridSummaryColumnDescriptor2.DataMember = "ISIN"; gridSummaryColumnDescriptor2.DisplayColumn = "QuoteSpreadTo"; gridSummaryColumnDescriptor2.Format = "{MaxString}"; gridSummaryColumnDescriptor2.Name = "ISINMax"; gridSummaryColumnDescriptor2.SummaryType = Syncfusion.Grouping.SummaryType.Custom; "{MaxString}" is a custom function. The data being summed up in this summary column is the same repeating data in each of the detail rows underneath the summary row. Is there a way I can accomplish this without using a custom summary type and having to use a custom function? Our goal for this summary function is to move the repeating value from the detail row to the summary row. The attached project will show this. SyncGroup101804_7031.zip

6 Replies

AD Administrator Syncfusion Team October 20, 2004 06:24 AM UTC

Hi Anthony, I needed to make the following changes in order to get your code running: Line 226 gridSummaryColumnDescriptor4.Format = "{Average:#,###.00}"; gridSummaryColumnDescriptor4.Name = "CurrentFaceAvg"; gridSummaryColumnDescriptor4.DataMember = "CurrentFace"; gridSummaryColumnDescriptor4.SummaryType = Syncfusion.Grouping.SummaryType.DoubleAggregate; gridSummaryColumnDescriptor5.DisplayColumn = "PositionCount"; gridSummaryColumnDescriptor5.Format = "{Average}"; gridSummaryColumnDescriptor5.Name = "PositionCountAvg"; gridSummaryColumnDescriptor5.DataMember= "PositionCount"; gridSummaryColumnDescriptor5.SummaryType = Syncfusion.Grouping.SummaryType.Int32Aggregate; (DataMember was not set) Line 714: string strISIN = (group.Category != null) ? group.Category.ToString() : "null"; (group.Category is always null for TopLevelGroup) Regarding your question about a built-in summary type for repeating values. No, there is no such summary. But your MaxStringSummary implementation should do the job. Let me know if you have any problems with the custom summary. Stefan


AA Anthony Avella October 21, 2004 02:12 PM UTC

My problem with using this MaxString function is that it seems to be quite slow. Do you have any reccomendations for speeding it up? Thanks


AA Anthony Avella October 21, 2004 03:54 PM UTC

Is it possible to override a value in a summary column with a value we want; instead of having to use a custom summary function?


AD Administrator Syncfusion Team October 21, 2004 06:53 PM UTC

Any value in any cell (also summary cells in caption bar) can be overriden when you handle the QueryCellStyleInfo event. When you fill the value for that specific column (check TableCellIdentity.Column) you can also access the first record of that group and get the value from there, e.g. private void gridGroupingControl1_QueryCellStyleInfo(object sender, GridTableCellStyleInfoEventArgs e) { Element el = e.TableCellIdentity.DisplayElement; if (el is CaptionRow) { // you can get the column as follows: GridColumnDescriptor column = e.TableCellIdentity.Table.GetColumnDescriptorAt(e.Style.TableCellIdentity.RowIndex+1, e.Style.TableCellIdentity.ColIndex); // - or GridColumnDescriptor column = e.TableCellIdentity.Column; // Using that column you could try and identify the summary that should be displayed in this cell. e.Style.CellValue = e.TableCellIdentity.ParentGroup.GetFirstRecord().GetValue(column.MappingName); } } Stefan


AA Anthony Avella October 22, 2004 02:44 PM UTC

Here is my event handling function: private void grid_QueryCellStyleInfo(object sender, Syncfusion.Windows.Forms.Grid.Grouping.GridTableCellStyleInfoEventArgs e) { try { Element theElement = e.TableCellIdentity.DisplayElement; string strColumn; if ((e.TableCellIdentity.TableCellType == GridTableCellType.RecordFieldCell || e.TableCellIdentity.TableCellType == GridTableCellType.AlternateRecordFieldCell) && e.TableCellIdentity.SummaryColumn == null) { e.Style.CellValue = ""; } if (theElement is CustomCaptionRow ) { e.Style.ReadOnly = false; if(e.TableCellIdentity.SummaryColumn != null) { Group group = e.TableCellIdentity.DisplayElement.ParentGroup; ISINModifiedColumnsProvider isiprov = (ISINModifiedColumnsProvider) group; //when a value is changed in a summary, this event is raised twice //(calling this handler twice) The second call does not do any updating //and the group is null. To avoid an error being raised, Syncfusion //has advised us to check for the null group variable. if(group.Category != null) { string strISIN = group.Category.ToString(); string strField = e.TableCellIdentity.SummaryColumn.DataMember; if (isiprov.ISINModifiedColumns.Contains(strISIN)) { Hashtable htModifiedColumns = (Hashtable) isiprov.ISINModifiedColumns[strISIN]; if (htModifiedColumns.Contains(strField)) { e.Style.CellValue = htModifiedColumns[strField].ToString(); } } } } else { } } } catch(Exception ex) { StackFrame sf = new StackFrame(); MethodBase mb = sf.GetMethod(); Global.DisplayError(ex, mb, sf); } } I tried adding the following 2 lines of code you sent me in the last reply beneath the ''if (theElement is CustomCaptionRow ) '' stmt of my function: GridColumnDescriptor column = e.TableCellIdentity.Table.GetColumnDescriptorAt(e.Style.TableCellIdentity.RowIndex+1, e.Style.TableCellIdentity.ColIndex); e.Style.CellValue = e.TableCellIdentity.DisplayElement.ParentGroup.GetFirstRecord().GetValue(column.MappingName); I kept getting an ''Object reference not set to an instance of an object'' error when the second line of code is executed (implying the first line of code didn''t return what it was intended to). My event handler is used to decide which detail cell values are hidden underneath a grouping''s summary row as well as ensure that a new value entered into a summary row stays in that row after the cell loses focus. In light of my goals stated in the beginning of this form chain please anwser the below questions for me: 1-How and where do these lines of code fit into my event handler? 2-Can you please explain the anwser to the above question? 3-Will these 2 lines of code affect the rest of the function''s logic? 4-On a bit of a side track, can you also explain what the e.TableCellIdentity.SummaryColumn property is? The documentation is a bit vague. Thank you very much for your continued help.


AD Administrator Syncfusion Team October 24, 2004 11:40 AM UTC

Hi Anthony, 1) add the following line before: if (column != null && column.MappingName == "MyColumnNameIWantToSupplySummaryFor") e.Style.CellValue = e.TableCellIdentity.ParentGroup.GetFirstRecord().GetValue(column.MappingName); Adding those lines inside the if branch for if (theElement is CustomCaptionRow ) is fine. 2) By checking for column.MappingName you can identify the specific column that you want to supply a value for. The line below will get the first record of the parent group of the current caption element and from this record get the value of the column. Best is if you split the lines: Group g = e.TableCellIdentity.ParentGroup; Record r = g != null ? g.GetFirstRecord() : null; object valueOfFirstRecord = r != null ? r.GetValue(column.MappingName) : null; e.Style.CellValue = valueOfFirstRecord; 3) The function should not interfere with your other functions logic as long as the column "MyColumnNameIWantToSupplySummaryFor" is not also in your ISINModifiedColumns hashtable. That should normally not be the case. The SummaryColumn will also be null once you do not add the CurrentFaceAvg and PositionCountAvg summary descriptors any more. 4) The TableCellIdentity.SummaryColumn is available for cells that are dependant on a summary descriptor to fill in the value. GridSummaryColumDescriptor has a DisplayColumn property. This property defines the target column at which to display the summary. If QueryCellStyleInfo is raised for the target column, then TableCellIdentity.SummaryColumn will have a reference to the associated summary column. Stefan

Loader.
Up arrow icon