Declined
Last Updated: 08 Jan 2025 09:23 by ADMIN
Martin
Created on: 06 Jan 2025 13:14
Category: UI for WinForms
Type: Bug Report
1
GridSummaryCellElement.Value should not return string

Repro-steps

  1. Create a RadGridView
  2. Add a GridViewDecimalColumn
  3. Add a GridViewSummaryRowItem with a GridViewSummaryItem which:
    1. calculates the average of the values in the decimal column
    2. formats the value to two decimals after the decimal point: {0:0.00}
  4. Make an event handler for ViewCellFormatting.
  5. Add some rows with values to the grid.
  6. In the event handler, try to read ((GridSummaryCellElement)e.CellElement).Value.

Actual behavior

The value contains a string representing the formatted and rounded value of the average of all values.

Expected behavior

The value contains a raw, not rounded,  not formatted, decimal value. 

Remarks

I expect this behavior since GridSummaryCellElement has two properties: Text and Value.
I expect those to have difference functions. Value to hold the actual calculated value, and Text to hold the formatted, round string-equivalent.

Another reason why I expect this, is that Value is of type object, not of type string. So expect a value corresponding to the original datatype of the column and/or the result of the calculation.

Follow-up questions

  1. In what scenario may I expect in Value another data type that string?
  2. How, during the event handler, can I retrieve the original calculated value (with using parsing, since that is slow and does not contain all the digits).

 

1 comment
ADMIN
Dinko | Tech Support Engineer
Posted on: 08 Jan 2025 09:23

Hello Martin,

I appreciate the listed steps to check this behavior. Indeed the GridSummaryCellElement Value property is string. Upon checking the code, the value of this cell will always be a string. I understand your point that itis kind of strange to have Text and Value, but the GridSummaryCellElement derives from GridCellElement and these properties are inherited. 

Now you will ask, still why the GridSummaryCellElement Value is string. By default, you can have more than one GridViewSummaryItem in one GridViewSummaryRowItem for one column. Check the following example:

GridViewSummaryItem summaryItem = new GridViewSummaryItem("NumberProperty", @"Avg {0:0.00}", GridAggregateFunction.Avg);
GridViewSummaryItem summaryItem2 = new GridViewSummaryItem("NumberProperty", @"  Count {0:0.00}", GridAggregateFunction.Sum);
GridViewSummaryRowItem summaryRowItem = new GridViewSummaryRowItem();
summaryRowItem.Add(summaryItem);
summaryRowItem.Add(summaryItem2);
this.radGridView1.SummaryRowsTop.Add(summaryRowItem);

You can observe that we have two functions: average and sum. The result of these two functions will be placed in one GridSummaryCellElement for that column. Here is how it looks:

The Value property of the GridSummaryCellElement will contain the result of both functions in our example. 

To summarize my reply, the Value property of the GridSummaryCellElement will be a string as you could have more than one function in one summary cell. That is why we don't consider this a bug.

To get the actual value of each function, you can use the GroupSummaryEvaluate event. This event will be called in our example, two times. For the average function and for the sum function. The Value property in the event arguments will be of type decimal as in my test project the bound property is of type decimal.

Regards,
Dinko | Tech Support Engineer
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.