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

is there a solution categorize a row and put it in two different group

2 Answers 27 Views
GridView
This is a migrated thread and some comments may be shown as answers.
alireza
Top achievements
Rank 1
alireza asked on 25 Jul 2011, 11:19 AM
i just want a solution to categorize a row and put it in two different group , is there any solution ?!
for example i have a list like below :

Id       -       Color
--------------------------------------------------------------
1  - blue , red
2 red
3 - blue , green

and want to group by color and have a output list like below :

group : red
--------------------------------------------------------------
1 - blue , red
2 - red

group : blue
--------------------------------------------------------------
1 - blue , red
3 - blue , green

group : green
--------------------------------------------------------------
3 - blue , green

2 Answers, 1 is accepted

Sort by
0
alireza
Top achievements
Rank 1
answered on 27 Jul 2011, 09:33 AM
Hi Guys

i m evaluating your grid , we are deciding on what grid to use please if there is no solution tell me.


tnx guys.
0
Julian Benkov
Telerik team
answered on 28 Jul 2011, 08:37 AM
Hi Alireza,

For this scenario you can use a custom grouping operation, but one row can not exist in two or more groups for a group level. The row can belong to only one group per level. Here is a small example:

public partial class GridForm4 : Form
{
    public GridForm4()
    {
        InitializeComponent();
         
        DataTable table = new DataTable();
        table.Columns.Add("ID");
        table.Columns.Add("Color");
 
        table.Rows.Add(1, "blue, red");
        table.Rows.Add(2, "red");
        table.Rows.Add(3, "blue, green");
         
        radGridView1.DataSource = table;
        radGridView1.ShowGroupedColumns = true;
        radGridView1.EnableCustomGrouping = true;
        radGridView1.CustomGrouping += new GridViewCustomGroupingEventHandler(radGridView1_CustomGrouping);
        radGridView1.GroupSummaryEvaluate += new GroupSummaryEvaluateEventHandler(radGridView1_GroupSummaryEvaluate);
    }
 
    void radGridView1_CustomGrouping(object sender, GridViewCustomGroupingEventArgs e)
    {
        string color = e.Row.Cells["Color"].Value.ToString();
        if (color == "blue, red" || color == "red")
        {
            e.GroupKey = "red";
        }
        else
        {
            e.GroupKey = "green";
        }
    }
 
    void radGridView1_GroupSummaryEvaluate(object sender, GroupSummaryEvaluationEventArgs e)
    {
        e.FormatString = e.Group.Key.ToString();
    }
}

Please view the result in attached screenshot.

I hope this information is useful.

 Kind regards,
Julian Benkov
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

Tags
GridView
Asked by
alireza
Top achievements
Rank 1
Answers by
alireza
Top achievements
Rank 1
Julian Benkov
Telerik team
Share this question
or