First I'm using the following:
I would like to allow the user to select the type of summary for a column, but the "Sum" is disabled for some reason.
My settings in the UltraWinGrid Designer are as follows:
For some reason when the user clicks on the column to dislplay your "Select Summaries" form and the "Sum" option is disabled. What do I need to set to have this enabled? From the Designer? By the way my program will display the sum total from code! But thats not the way we want this to work.
Also I tried inserting pictures for your benifit, but alas YOUR posting form will not accept any! Whats up with that?
Thanks ahead of time.
Patrick
Hello Patrick,
Have you been able to check what is the DataType of the column in DesignTime? By default the DataType of the added columns in design time is System.String, and the "Sum" and "Avarage" options will be disabled.
Please let us know if you have any further questions.
Hi
Is there are way of intercepting this rule in code ?
I am displaying a list of time balances (hours) in the format 37:30, 40:00, obviously we need to display them as strings to format them this way.
It would be good to see the sum and average, even if it means converting these to minutes (integers), calculate the Sum and Average and reformat these as SUM = HH:MM, AVERAGE = HH:MM.
Is this possible ?
thanks
Simon G
Hi Simon,
There is no support in the DotNet framework for formatting a string. So if the DataType of your column is a string, this will be very difficult.
What's the actual DataType of the grid column?
Hi Mike
I think you mean there is no support in DotNet for formatting an integer...
But anyway, the DataType is string but we were wanting to know if we could get into the behind-the-scenes code that is called when clicking the Sigma on the UltraGrid - and tailor it.
Hi,
sgarstin said:I think you mean there is no support in DotNet for formatting an integer...
No, that is not what I meant. I meant string.
You can format an integer by calling the ToString method and passing in a format. This is true of all numeric and date types. The string data type is the one that does not have an overload of ToString that takes in a format. So you cannot format a string.
sgarstin said:But anyway, the DataType is string but we were wanting to know if we could get into the behind-the-scenes code that is called when clicking the Sigma on the UltraGrid - and tailor it.
I'm not quite sure exactly what your goal is here, so it's tough to answer the question.
Storing numeric data as a string is a really bad idea. This will cause all sorts of problems. Sorting, filtering, and summaries will all have problems. So if you can, you are much better off storing your numbers in a numeric type and then simply formatting the display.
If you want to store your data as strings, then the only way you could make the summaries work is to handle them yourself. You can do this by using an ISummaryCalculator. What you would have to do is handle the Before/AfterSummaryDialog event. You could examine the summaries that exist and then replace them with Summaries of your own that do your own custom summary calculations. But this is a lot more work than just formatting the display. And it won't help with sorting or filtering, so if you want to use those features, you will have to add similar code to handle those operations manually.
I think we're taking slightly cross-purposes... and possibly there is confusion over terminology ;)
The actual time value is in minutes and is stored as an integer in the database and treated as an integer elsewhere in the code.
Also, when you talk about "storing" do you actually mean "displaying in the ultragrid" ?
We want to display this value in the Ultragrid but not as minutes (ie. 95) but in HH:MM format "01:35" and so are using ToString() (with format parameters) before assigning it to the ultragrid column. However because it is a string in the Ultragrid, Sum and Average are greyed out.
You stated "So if you can, you are much better off storing your numbers in a numeric type and then simply formatting the display."
Do you mean "storing" it as an integer in the Ultragrid ? Once the value is assigned as an integer to an Ultragrid column, however do you format (to a string) it after that ?
The order I am doing this is:
(1) Value is integer = 95
(2) Format to string = "01:35"
(3) Assign "01:35" to Ultrgrid column
(4) Ultragrid displays "01:35" (what we want) but Sum and Averrage are greyed out.
How else would this be done (if we want to retain the HH:MM format in the Ultragrid)
Simon
So how are you currently taking the integer value and formatting it for display in the grid as a string?
Also... is this field editable by the user?
There's no built-in support in DotNet for taking an integer and formatting it as hours and minutes except maybe by creating a TimeSpan object.
But if this field is not editable, then it would be very easy for you to format the data using your own custom FormatProvider.
No, I don't think any of the dotnet data types support this format. But it should be enough to take an int and divide by 60 to get the hours and use the mod to get the minutes and build a string out of it.
To clarify:
I'm not sure if it's possible to convert an integer to a datetime HH:MM format in a single format command..,
regds ;)
Thanks for getting back to me and I agree, the first option seems the better one.
I'm not sure if it's possible to convert an integer to a datetime HH:MM format but will investigate - if you have an examples to hand that would be useful too ;)
Thanks for the continued support.
Sorry I didn't answer your first question:
The time is stored in a custom object WorkingTime and the formatting code is:
return String.Format("{0}:{1:00}", workingTime.Hours, workingTime.Minutes);
workingTime.Hours, workingTime.Minutes are both INTS
Okay... if the cell is not editable, that makes things a lot easier.
You are correct, the Format property won't help you by itself, because there isn't any support in the DotNet framework for formatting an int as hours and minutes.
There are basically two approaches you can take here.
1) Keep using Int and use Format and FormatProvider to do custom formatting. You can create your own IFormatProvider which will handle your own custom Format strings and format the int however you want it.
2) You could use Timespan and enable to the sum and average options by setting AllowRowSummaries on the column to True (instead of the default, which is BasedOnDataType). Of course, the grid won't know how to perform the sum or average on a TimeSpan column, so you would have to manually handle the actual calculations, also. How you do this will depend greatly on what version of the grid you are using.
Personally, I think option 1 is your best bet. Writing your own FormatProvider is pretty easy and you will be able to use the same FormatProvider and the same Format for both the column itself and the summaries.