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

GroupByExpression

5 Answers 152 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Khizar Khan
Top achievements
Rank 1
Khizar Khan asked on 18 May 2010, 12:45 PM
Hi,

I have GridView which is a flat structure allowing the user to group by most of the columns.

for e.g. i am trying to show the task list of the user where I have

Priority, Task Name, Task Desc, Source, Count as columns
High, Process A, Account:123, Mobile, 20 as row
High, Process A, Account 124, Web, 40 as row
Low.....
Med....

my questions are:
1. can we disqualify some of the columns to be used by groupby by the user.
2. When I group by priority column, I shoud get the count next to the group by column, I have enclosed the ping with the image and what I want (marked in red). I want to get rid of the count column in the display and the summary row.

any advice with sample program will of great help and thanks in advance.

Regards,
Khizar

5 Answers, 1 is accepted

Sort by
0
Jack
Telerik team
answered on 18 May 2010, 10:13 PM
Hello Khizar Khan,

Regarding your questions:

1. You can disable grouping for specific columns in RadGridView by setting the AllowGroup property to false. Here is a sample:

this.radGridView1.Columns["Name"].AllowGroup = false;

2. You can fully customize the group row text by handling the GroupSummaryEvaluate method. You can find a sample in this blog article.

I hope this helps. If you need further assistance, please write back.

Greetings,
Jack
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
erwin
Top achievements
Rank 1
Veteran
Iron
answered on 19 May 2010, 08:36 AM
Khizar Khan,

This is the code I use to display the number of contained records in the group summary.

void MyGridView_GroupSumaryEvaluate(object sender, GroupSummaryEvaluationEventArgs e) 
        { 
            string suff = String.Concat(" (", e.Group.RowCount.ToString(), ")"); 
 
            if(e.FormatString.EndsWith(";")) 
            { 
                e.FormatString = e.FormatString.Substring(0, e.FormatString.Length - 1); 
            } 
 
            if (!e.FormatString.EndsWith(suff)) 
            { 
                e.FormatString = String.Concat(e.FormatString, suff); 
            } 
        } 

The code handles some strange occasions where the GroupSumaryEvaluate is called multiple times.

Regards
Erwin





0
Khizar Khan
Top achievements
Rank 1
answered on 19 May 2010, 11:41 AM
Thanks a lot for the advice.

where do i find the atricle on GroupSummaryEvaluate, can you please give me the link?

for groupby - my requirement is a bit different, i don't want the rowcount when you group by, rather it will be the sum of count(column) in the dataset (which I want to make it invisible), so every group by will have the sum of count(column) based on the filtered rows along with teh groupby field name. The png attached in my original post will show the requirement a bit clearer.

also to add to this, i want to limit the groupby field to be added by the user to a maximum of 4. any suggestion how to achieve this?

regards,
Khizar


0
Khizar Khan
Top achievements
Rank 1
answered on 19 May 2010, 11:50 AM
Hi,

I have tried to limit the group by fields by the following code. is this how we need to do this? or is there a better way.

 
 void GroupByExpressions_CollectionChanged(object sender, Telerik.WinControls.Data.NotifyCollectionChangedEventArgs e)
        {
            if (this.radGridView1.MasterGridViewTemplate.GroupByExpressions.Count > 4)
            {
                MessageBox.Show("Max Groupby fields can be is 4. Please remove some before adding");
                this.radGridView1.MasterGridViewTemplate.GroupByExpressions.RemoveAt(4);
                return;
            }
        }

0
Khizar Khan
Top achievements
Rank 1
answered on 19 May 2010, 03:12 PM
Thanks Erwin,

Yes, I have tried your solution and it works.

first is to have a summary row with a summary item

GridViewSummaryRowItem item1 = new GridViewSummaryRowItem();  
 item1.Add(new GridViewSummaryItem("Count", "Count: {0} ", GridAggregateFunction.Sum)); 
 this.radGridView1.MasterGridViewTemplate.SummaryRowsBottom.Add(item1); 

then subscribe to GroupSumaryEvaluate event.

In the event. it is available as aggregate row for each group

void radGridView1_GroupSumaryEvaluate(object sender, GroupSummaryEvaluationEventArgs e) 
        { 
            try 
            { 
                string suff = ""
 
                foreach (Aggregate item in e.Group.Aggregates) 
                { 
                    if (item.FieldName == "Count") suff = String.Concat(" (", item.Value.ToString(), ")"); 
                } 
 
                if (e.FormatString.EndsWith(";")) 
                { 
                    ee.FormatString = e.FormatString.Substring(0, e.FormatString.Length - 1); 
                } 
 
                if (!e.FormatString.EndsWith(suff)) 
                { 
                    e.FormatString = String.Concat(e.FormatString, suff); 
                }  
            } 
            catch (Exception exp) 
            { 
                MessageBox.Show(exp.Message + System.Environment.NewLine + exp.StackTrace.ToString()); 
                 
                throw; 
            } 
            
             
        } 

thanks for all the help.

These controls are really good and I enjoying working on these.

Regards,
Khizar



Tags
GridView
Asked by
Khizar Khan
Top achievements
Rank 1
Answers by
Jack
Telerik team
erwin
Top achievements
Rank 1
Veteran
Iron
Khizar Khan
Top achievements
Rank 1
Share this question
or