Mike,
I am using Ultrawingrid and i have a column to get time value. For the time column, i am using the Style as "Time". I set the maskinput as "hh:mm:ss". The datatype of this column is string.
For this column i need the summary. Is it possible to set summary for the time values? I tried to set the summary using summary row but it is not working. Guide me to get the summary for this time column.
Hi,
The grid's built-in summaries will not work on a String field. The grid has no way to add strings together.
You could use an ICustomSummaryCalculator and write your own code to convert the string into a date and perform the summary calculations yourself.
My advice would be to use a DateTime or a TimeSpan data type for the column. Storing numeric or date values as string is generally not a good idea and will cause you all sorts of problems with sorting, filtering, and calculating.
I changed the datatype as "datetime" but also the summary not coming. I attached a sample source for your reference.
At the load, i added the summary for the filed. If i enter time value, the summary will not display.
I have some coding in the "ugBalanceSheet_SummaryValueChanged" event, which calculate the value and post it in summary. Is there any simple way to work out this summary than my coding?
There's a whole lot going on in this sample, so it's hard to tell what I should be looking at. I assume the summary you are talking about is this one:
qbGrdSummary = ugBalanceSheet.DisplayLayout.Bands(0).Summaries.Add(ugBalanceSheet.DisplayLayout.Bands(0).Columns(5).Key & "###Time", _ "sum([unboundcolumn2])", SummaryPosition.UseSummaryPositionColumn, _ ugBalanceSheet.DisplayLayout.Bands(0).Columns("unboundcolumn2"))
So this is a formula summary which is doing a sum. But sum doesn't make sense for a DateTime column. There is no addition (+) operator defined for the DateTime data type. Adding a DateTime to another DateTime has no meaning.
To verify this, I changed "sum" to "count". Count makes sense regardless of the data type and count works correctly.
I think if you want to do sums, you would have to use TimeSpan as the type for this column. Or, as I said, you could use an ICustomSummaryCalculator.
Thanks for your information. Before this post i wrote some coding in the "Grid_Summaryvaluechanged" and handled this time column summary. Now i used a class with Icustomcalculatorsummary as below.
Public
Class TimeSummaryCalculator Implements ICustomSummaryCalculator
'Class added by suresh to calculate the time value in grid and post it to the summar (08/07/11) -R_Summary_02
#Region "ICustomSummaryCalculator Procedures & Functions"
Dim loValue As Object = row.Cells(summarySettings.SourceColumn).Value
lnSeconds += QbConvert(loValue,
"T", "S")
End Sub
lnSeconds = 0
Return QbConvert(lnSeconds, "S", "T")
End Function
End
Class
I called this class as below :
QbGrdSummary = .Summaries.Add(QbGrid.DisplayLayout.Bands(lnBand).Columns(Irow).Key, SummaryType.Custom, _
New TimeSummaryCalculator, QbGrid.DisplayLayout.Bands(lnBand).Columns(Irow), loSummaryPosition, _
QbGrid.DisplayLayout.Bands(lnBand).Columns(Irow))
It is working fine (QbConvert is my function which converts time to seconds and viceversa). Thanks for support