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

Selecting rows with multi-level Grouping

5 Answers 350 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Taz
Top achievements
Rank 1
Taz asked on 06 Jan 2010, 07:29 PM
Hello,


I have a grid with 3 levels of grouping.

1- Department
   2- Employee
      3-Wage Code

I use server side code to a a checkbox to the Department Group header in the RadGrid_Prerender (is that the right way to do it??)
So now I need to be able to click on that check box and have it SELECT ONLY the records in that particular groud (e.g. depart)

See attached image.


5 Answers, 1 is accepted

Sort by
0
Jack
Telerik team
answered on 08 Jan 2010, 01:19 PM
Hi Peter Giannopoulos,

Thank you for writing us. As I understand you want to place a checkbox inside the group header row. This functionality is not build in RadGridView, so you have to use custom cell elements. The header row is not a data row and it has no representation in the underlying data source. However, you can use the Tag property to save the group state (on or off). Please consider the code snippet below:

void radGridView1_CreateCell(object sender, GridViewCreateCellEventArgs e)
{
    if (e.Row is GridGroupHeaderRowElement && e.Column == null)
    {
        e.CellType = typeof(MyGroupCell);
    }
}
 
 
public class MyGroupCell: GridCellElement
{
    RadCheckmark checkmark;
    LightVisualElement label;
 
    public MyGroupCell(GridViewColumn column, GridRowElement row): base(column, row)
    {
    }
 
    protected override Type ThemeEffectiveType
    {
        get { return typeof(GridCellElement); }
    }
 
    public override void UpdateInfo()
    {
        base.UpdateInfo();
        if (this.RowInfo.Tag != null && (bool)this.RowInfo.Tag == true)
        {
            this.checkmark.CheckState = Telerik.WinControls.Enumerations.ToggleState.On;
        }
        else
        {
            this.checkmark.CheckState = Telerik.WinControls.Enumerations.ToggleState.Off;
        }
    }
 
    protected override void CreateChildElements()
    {
        base.CreateChildElements();
        checkmark = new RadCheckmark();
        checkmark.Alignment = ContentAlignment.MiddleCenter;
        checkmark.ShouldHandleMouseInput = true;
        checkmark.MouseDown +=new MouseEventHandler(checkmark_MouseDown);           
        label = new LightVisualElement();
        label.ShowHorizontalLine = true;
        label.BindProperty(LightVisualElement.TextProperty, this, LightVisualElement.TextProperty, PropertyBindingOptions.OneWay);
        StackLayoutPanel panel = new StackLayoutPanel();
        panel.Orientation = Orientation.Horizontal;
        panel.Children.Add(checkmark);
        panel.Children.Add(label);
        this.Children.Add(panel);
    }
 
    protected override void PaintText(Telerik.WinControls.Paint.IGraphics graphics)
    {
    }
 
    private void checkmark_MouseDown(object sender, MouseEventArgs e)
    {
        if (checkmark.CheckState == Telerik.WinControls.Enumerations.ToggleState.On)
        {
            checkmark.CheckState = Telerik.WinControls.Enumerations.ToggleState.Off;
            this.RowInfo.Tag = false;
            CheckSubGroups(((GridViewGroupRowInfo)this.RowInfo).Group, false);
        }
        else
        {
            checkmark.CheckState = Telerik.WinControls.Enumerations.ToggleState.On;
            this.RowInfo.Tag = true;
            CheckSubGroups(((GridViewGroupRowInfo)this.RowInfo).Group, true);
        }
    }
 
    private void CheckSubGroups(DataGroup group, bool state)
    {
        foreach (DataGroup subGroup in group.Groups)
        {
            subGroup.HeaderRow.Tag = state;
            subGroup.HeaderRow.InvalidateRow();
            CheckSubGroups(subGroup, state);
        }
    }
}

 

You should iterate the Groups collection of RadGridView to get the checked group rows:

List<GridViewGroupRowInfo> GetCheckedGroupRows(RadGridView grid)
{
    List<GridViewGroupRowInfo> checkedRows = new List<GridViewGroupRowInfo>();
    foreach(DataGroup group in grid.Groups)
    {
        if (group.HeaderRow.Tag != null && (bool)group.HeaderRow.Tag == true)
        {
            checkedRows.Add(group.HeaderRow);
        }
    }
    return checkedRows;
}

 

If you have any further questions, I will be glad to answer them.

 

All the best,
Jack
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
swarupa
Top achievements
Rank 1
answered on 04 Oct 2016, 01:07 PM

Hi,

I have a three level gridview in winform.

The parent(first level) and the third level gridviews have check box column. The second level gridview doesnot have checkbox column

1)How to change the togglestate of the checkboxes  present in all the corresponding records of the third level gridview  when the  checkbox is checked in  a particular row in the first level gridview

2) And Viceversa ...How to change the toggle state of the corresponding  checkboxes in parent (first level ) gridview  programmatically when the checkboxes are checked in the third level gridview

 

Thanks And Regards,

Bavya

 

 

 

 

0
Hristo
Telerik team
answered on 05 Oct 2016, 04:34 PM
Hi ,

Thank you for writing.

If I understand correctly you have set up the grid in a hierarchy. In order to accomplish your task, you would need to iterate the rows of the child template for a given hierarchy row. The following documentation article provides an example:  http://docs.telerik.com/devtools/winforms/gridview/hierarchical-grid/how-to/iterating-the-child-rows-collection-of-a-chosen-parent-row-in-hierarchy-radgridview.

When you are in your third level you would need to iterate the rows in your master template. For the purpose you can handle the CellValueChanged event: 
private void radGridView1_CellValueChanged(object sender, GridViewCellEventArgs e)
{
    if (e.Row.HierarchyLevel == 2)
    {
        foreach (GridViewRowInfo row in this.radGridView1.MasterTemplate.Rows)
        {
            //...
        }
    }
}

I hope this helps. Should you have further questions please do not hesitate to write back.

Regards,
Hristo Merdjanov
Telerik by Progress
Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms. For more information check out this blog post and share your thoughts.
0
swarupa
Top achievements
Rank 1
answered on 06 Oct 2016, 12:36 PM

Hi Hristo,

Thank you very much for the quick response.

When I check the check box in a parent row, the checkboxes in child records and corresponding grand child records are checked programmatically with the following code.

foreach (GridViewRowInfo r in e.Row.ChildRows)
{

r.Cells["column2"].Value = e.Value;
foreach (GridViewRowInfo i in r.ChildRows)
{
i.Cells["column3"].Value = e.Value;

}

}

Similarly how can I check or uncheck the check box of the parent row programmatically, when all the checkboxes of the corresponding child rows are checked or unchecked?

Thanks And Regards,

Bavya

 

0
Hristo
Telerik team
answered on 07 Oct 2016, 11:41 AM
Hi ,

Thank you for writing back.

The CellValueChanged event provides information about the hierarchy level of the cell. I can suggest accessing the grid templates depending on that level and perform the required custom logic.

I hope this information helps. Should you have further questions please do not hesitate to write back.

Regards,
Hristo Merdjanov
Telerik by Progress
Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms. For more information check out this blog post and share your thoughts.
Tags
GridView
Asked by
Taz
Top achievements
Rank 1
Answers by
Jack
Telerik team
swarupa
Top achievements
Rank 1
Hristo
Telerik team
Share this question
or