This is a migrated thread and some comments may be shown as answers.

Little problem with group by

1 Answer 66 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Fabien
Top achievements
Rank 2
Fabien asked on 06 Feb 2009, 09:37 AM
Hi,

I have a little problem with group by display.

I have :
pRadGridView.MasterGridViewTemplate.GroupByExpressions.Add("Something1 as Brand format \"{1} - \",sum(Price) as TotalPrice format \"{1} €\" Group By Something1"); 
 
pRadGridView.MasterGridViewTemplate.GroupByExpressions.Add("Something2 as Size format \"{1} - \",sum(Price) as TotalPrice format \"{1} €\" Group By Something2"); 
 
pRadGridView.MasterGridViewTemplate.GroupByExpressions.Add("Something3 as DontCare format \"{1} - \",sum(Price) as TotalPrice format \"{1} €\" Group By Something3"); 

column definition
            GridViewDataColumn Price_Column = new GridViewDataColumn("Price""Price"); 
            Price_Column.HeaderText = "Prices"
            Price_Column.FormatString = "{0:N2}"
            Price_Column.IsVisible = false
            Price_Column.DataType = typeof(decimal); 
            pRadGridView.MasterGridViewTemplate.Columns.Add(Price_Column); 

The problem is.... what's displayed. I can see :

MyBrand1 - 100.00 €
    Size1 - 50.00 €
         DontCare1 - 25.00 €
         DontCare2 - 25 €
    Size2 - 50.00 €
        DontCare1 - 20 €
        DontCare2 - 30 €
MyBrand2 - 300.00 €
    Size1 - 50.00 €
         DontCare1 - 25 €
         DontCare2 - 25 €
    Size2 - 50.00 €
        DontCare1 - 20 €
        DontCare2 - 30.00 €

Sometime I can see the #.##, and I don't know why, sometime #.

I bind column like this :
// subTotal is a sum a other columns, and it's int value :) 
row.Cells["Price"].Value = subTotal * Math.Round(StreetPriceEuro, 2); 

I change colors of "Expanders" with this code (I don't do anything else with "them") in ViewCellFormatting event
                // Custom expanders colors 
                if (pGridCellElement.RowInfo is GridViewGroupRowInfo && pGridCellElement.RowElement is GridGroupHeaderRowElement) 
                { 
                    int level = ((GridViewGroupRowInfo)pGridCellElement.RowInfo).Group.Level; 
 
                    if (level == 3) pGridCellElement.ForeColor = Color.FromArgb(31, 71, 79); 
                    if (level == 4) pGridCellElement.ForeColor = Color.FromArgb(50, 115, 128); 
                    if (level == 5) pGridCellElement.ForeColor = Color.FromArgb(70, 161, 179); 
 
                    pGridCellElement.HorizontalLineColor = pGridCellElement.ForeColor; 
                    return
                } 

Can you explain me why sum is rounded sometime ? because, I don't mind if my value is an int, My customer want to diplay the ".00".

Thank's

Fabien



1 Answer, 1 is accepted

Sort by
0
Jack
Telerik team
answered on 09 Feb 2009, 11:11 AM
Hello Fabien,

You should use the same formatting in your group expression. I changed the code a little. Take a look at it:

pRadGridView.MasterGridViewTemplate.GroupByExpressions.Add("Something1 as Brand format \"{1} - \",sum(Price) as TotalPrice format \"{1:N2} €\" Group By Something1");  
  
pRadGridView.MasterGridViewTemplate.GroupByExpressions.Add("Something2 as Size format \"{1} - \",sum(Price) as TotalPrice format \"{1:N2} €\" Group By Something2");  
  
pRadGridView.MasterGridViewTemplate.GroupByExpressions.Add("Something3 as DontCare format \"{1} - \",sum(Price) as TotalPrice format \"{1:N2} €\" Group By Something3"); 


Should you have any other questions, please write me back.

Sincerely yours,
Jack
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
GridView
Asked by
Fabien
Top achievements
Rank 2
Answers by
Jack
Telerik team
Share this question
or