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

Selective Grouping in GridView

4 Answers 63 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Frank
Top achievements
Rank 1
Frank asked on 03 Feb 2016, 10:00 PM

I have a grid that has columns such as Job number and Admin Name. 

 

I am grouping the rows by the Job Number. But I only want them to be grouped when there is more than one record. The user wants to see the +sign only when there is more than one admin per Job. is this possible? Can you help me find a solution for this?

 

Thank you. 

4 Answers, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 04 Feb 2016, 11:05 AM
Hello Frank,

Thank you for writing.

If I understand your requirement correctly, you are trying to hide the group row element if the group has only 1 record in it. For this purpose, it is suitable to use the ViewRowFormatting event and set the GridGroupHeaderRowElement.RowInfo.Height property to 1. It is important to expand the group in order to display this single record. Here is a sample code snippet:
public Form1()
{
    InitializeComponent(); new RadControlSpyForm().Show();
 
    DataTable dt = new DataTable();
    dt.Columns.Add("JobNumber", typeof(string));
    dt.Columns.Add("AdminName", typeof(string));
 
    dt.Rows.Add("fp0011450", "UMB Fund Services");
    dt.Rows.Add("fp0011452", "M3Sixty Fund Services");
    dt.Rows.Add("fp0011452", "M3Sixty Fund Services");
    dt.Rows.Add("fp0011452", "M3Sixty Fund Services");
    dt.Rows.Add("fp0011452", "M3Sixty Fund Services");
    dt.Rows.Add("fp0011453", "UMB Fund Services");
    dt.Rows.Add("fp0011454", "Lavanya Funds");
    dt.Rows.Add("fp0011454", "Lavanya Funds");
 
    this.radGridView1.DataSource = dt;
    this.radGridView1.AutoSizeColumnsMode = Telerik.WinControls.UI.GridViewAutoSizeColumnsMode.Fill;
}
 
 
private void radGridView1_ViewRowFormatting(object sender, RowFormattingEventArgs e)
{
    GridGroupHeaderRowElement groupRow = e.RowElement as GridGroupHeaderRowElement;
    if (groupRow!=null)
    {
        if (groupRow.RowInfo.ChildRows.Count == 1)
        {
            groupRow.RowInfo.Height = 1;
            groupRow.RowInfo.IsExpanded = true;
        }
        else
        {
            groupRow.RowInfo.Height = 20;
        }
    }
}

Note that this is just a sample approach and it may not cover all possible cases. Feel free to modify it in a way which suits your requirement best.

I hope this information helps. Should you have further questions I would be glad to help.
 
Regards,
Dess
Telerik
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 Feedback Portal and vote to affect the priority of the items
0
Frank
Top achievements
Rank 1
answered on 04 Feb 2016, 01:36 PM

Thank you Dess. It worked like a charm. 

I also want the groupby column(in this case, Job number column) to show up in the row as well. 

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 04 Feb 2016, 03:26 PM
Hello Frank,

Thank you for writing back. 

In order to show the grouped column in the row as well, you should set the RadGridView.MasterTemplate.ShowGroupedColumns property to true.
this.radGridView1.MasterTemplate.ShowGroupedColumns = true;

I hope this information helps. If you have any additional questions, please let me know.

Regards,
Dess
Telerik
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 Feedback Portal and vote to affect the priority of the items
0
Frank
Top achievements
Rank 1
answered on 04 Feb 2016, 03:31 PM
Thank you Dess. 
Tags
GridView
Asked by
Frank
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Frank
Top achievements
Rank 1
Share this question
or