GroupByExpression

6 posts, 0 answers
  1. Khizar Khan
    Khizar Khan avatar
    41 posts
    Member since:
    Jan 2010

    Posted 18 May 2010 Link to this post

    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
  2. Jack
    Admin
    Jack avatar
    2335 posts

    Posted 18 May 2010 Link to this post

    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.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. erwin
    erwin avatar
    358 posts
    Member since:
    Dec 2006

    Posted 19 May 2010 Link to this post

    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





  5. Khizar Khan
    Khizar Khan avatar
    41 posts
    Member since:
    Jan 2010

    Posted 19 May 2010 Link to this post

    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


  6. Khizar Khan
    Khizar Khan avatar
    41 posts
    Member since:
    Jan 2010

    Posted 19 May 2010 Link to this post

    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;
                }
            }

  7. Khizar Khan
    Khizar Khan avatar
    41 posts
    Member since:
    Jan 2010

    Posted 19 May 2010 Link to this post

    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



Back to Top
UI for WinForms is Visual Studio 2017 Ready