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

RadGridView Header Text Grouping

5 Answers 376 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Dane Henry
Top achievements
Rank 1
Dane Henry asked on 25 Oct 2007, 09:10 PM
How do I create a group by expression string where the Header Text doesn't include datafield from the group by? Is this possible? I tried this with your RadGridView Grouping example and it does not work. I tried adding City, and Country but is doesn't display.  Please help

ShipName as Ship format "{0} --- {1} --- ",  Country, City, count(Ship) as shipments format "{1} {0}" Group By Ship

5 Answers, 1 is accepted

Sort by
0
Dwight
Telerik team
answered on 28 Oct 2007, 10:43 AM
Hi Dane,

On the left side of the Group By clausus in a Group-by expression you can only use fields that are on the right side or aggregate functions. Here is an example:
 

Country

City

Population

USA

New York

16

USA

Washington

10


For group-by expression: Country, sum(Population) Group By Country
The group header for USA will be: Country: USA, Population: 26

If you use Country, City, sum(Population) Group By Country the following issue arises: the value for Country  is obviously USA, the sum of all values in the population column for the group is 26. The problem is with the City as the column has multiple different values (New York and Washington in this example). There is no rule which one value is to be displayed.

The example above shows that only aggregate functions and fields included in the Group-by clause are eligible for for being displayed in the group header.

If you have questions and/or suggestions, don't hesitate to contact us. We will be glad to discuss them with you.

 
Regards,
Evtim
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Dane Henry
Top achievements
Rank 1
answered on 29 Oct 2007, 02:50 PM
If grouped by "Country, sum(Population) Group By Country" how do I prevent Country from being displayed in the header text.  Also do the "last" and "first" aggregate functions take only a numeric parameter.

Also, when the group header is selected how do I get the value of the details cells. For example when you grouped by "Country, sum(Population) Group By Country" how do you get the value of the first city if the group header is selected.
0
Jack
Telerik team
answered on 30 Oct 2007, 09:45 AM
Hello Dane,

You can control what is displayed in the group header by using the following format:
"Country format '{1}   remove {0} from the format string', sum(Population) format 'the population is {1}' Group By Country"

In the format string you can use {0} for the field name / alias, and {1} for the value that should be displayed. In fact, you can skip both {0} and {1} from the formatting, meaning that neither the field name/alias nor the value will be displayed.

Here's another example:
"Country format 'The population of {1} is', sum(Population) format '{1}' Group By Country"

To get the value of the first city when a group header is selected use the following code:

GridViewHeaderRowInfo header = (GridViewHeaderRowInfo)this.radGridView1.CurrentRow; 
if (header != null && header.Rows.Count > 0) 
    string city = header.Rows[0].Cells["City"].Value.ToString(); 
 

If additional questions arise, drop us a line. We will be glad to help.

Best wishes,
Jack
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Dane Henry
Top achievements
Rank 1
answered on 30 Oct 2007, 01:02 PM
Thanks for the info....

I have some issue with the code for getting the city value when the header is selected. The header.Rows[0] returns the currently selected row ( the header) which has a null value for the city.  Only when the details row is selected I am able to access the city values.
0
Jack
Telerik team
answered on 30 Oct 2007, 03:29 PM
Hi Dane Henry,

We suggest placing this code inside the CurrentRowChanged event. Inside this event you can check whether the CurrentRow is set to the right row.

In the sample code we assume also that you have only one level of grouping. If you continue to experience problems with solving this issue, send us your application.

Contact us again in case you have any other questions.

Sincerely yours,
Jack
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
GridView
Asked by
Dane Henry
Top achievements
Rank 1
Answers by
Dwight
Telerik team
Dane Henry
Top achievements
Rank 1
Jack
Telerik team
Share this question
or