
mark thompson
Top achievements
Rank 1
mark thompson
asked on 17 Feb 2010, 03:11 PM
Hi,
I have seen in other posts about problems with group by format strings. However that post was quite old, I'm using the Q3 2009 build.
When my users select a column to group by the format string that was with the column seems to be lost. i.e. if I have values £12.45 when that field is grouped it is displayed as 12.4500. I've seen an old solution which is supply the format string with the "group by" but I'm not programming the column; I just populate the grid with data and users take advantage of the group by bar.
How could I resolve this?
mark
I have seen in other posts about problems with group by format strings. However that post was quite old, I'm using the Q3 2009 build.
When my users select a column to group by the format string that was with the column seems to be lost. i.e. if I have values £12.45 when that field is grouped it is displayed as 12.4500. I've seen an old solution which is supply the format string with the "group by" but I'm not programming the column; I just populate the grid with data and users take advantage of the group by bar.
How could I resolve this?
mark
4 Answers, 1 is accepted
0

mark thompson
Top achievements
Rank 1
answered on 22 Feb 2010, 09:33 AM
In case anyone else gets this.
When a column is dragged to the "drag a column here to group" section. The group by expression creates a format string of:
{0}: {1};
which is pretty basic, even if you had a format string on that column.The workaround: add a handler to the GroupByChanging event on the Grid.
private void radGridView1_GroupByChanging(object sender, Telerik.WinControls.UI.GridViewCollectionChangingEventArgs e)
{
// for each group by expression in the new columns
foreach (GridGroupByExpression expression in e.NewItems)
{ // for each field
foreach (GridGroupByField field in expression.GroupByFields)
{
if (field.FieldName == "UnitPrice")
{
// the original format string {0}: {1};
field.FormatString =
"{0}: {1:$#,###0.00;($#,###0.00);0};";
}
}
}
}
this is a simplistic approach to finding what format string you should use but is seems to do the job
m
0
Hi mark thompson,
I am glad that you found the right solution. I have updated your Telerik points for sharing your code with the community. Do not hesitate to contact us again if you have any additional questions.
Kind regards,
Martin Vasilev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
I am glad that you found the right solution. I have updated your Telerik points for sharing your code with the community. Do not hesitate to contact us again if you have any additional questions.
Kind regards,
Martin Vasilev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0

Alex
Top achievements
Rank 1
answered on 10 Mar 2011, 07:34 PM
More generic and easer approach:
void radGridView1_GroupSummaryEvaluate(object sender, Telerik.WinControls.UI.GroupSummaryEvaluationEventArgs e)
{
var column = ((Telerik.WinControls.UI.MasterGridViewTemplate)sender).Columns[e.SummaryItem.Name];
e.FormatString = column.HeaderText + ": " + string.Format(column.FormatString, e.Value);
}
void radGridView1_GroupSummaryEvaluate(object sender, Telerik.WinControls.UI.GroupSummaryEvaluationEventArgs e)
{
var column = ((Telerik.WinControls.UI.MasterGridViewTemplate)sender).Columns[e.SummaryItem.Name];
e.FormatString = column.HeaderText + ": " + string.Format(column.FormatString, e.Value);
}
0
Hi Alex,
Thank you for your code. I have updated your Telerik points for contributing to this forum topic with your solution.
Best wishes,
Martin Vasilev
the Telerik team
Thank you for your code. I have updated your Telerik points for contributing to this forum topic with your solution.
Best wishes,
Martin Vasilev
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!