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

how to use a checkbox in a hierarchy grid as select all?

6 Answers 409 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Daniel Sprague
Top achievements
Rank 1
Daniel Sprague asked on 12 Mar 2010, 05:54 PM

I've got a hierarchy gridView in my winform that allows the user to pick items to include. 
In the hierarchy the parent is a "category", and the child rows are "category items".
In the grid, there's 2 columns for both the parents and children: a checkbox (Include?) and a textbox ("category name" for parent rows, "item name" for child rows).

The checkbox in the parent row in the grid is equivalent to a "Select All" at the top of a grid used to check all items, but instead of checking all items in the grid, when check, only the checkbox of it's child rows should be checked.  This way the user can pick individual "items" to include, or all items in a category, by clicking one checkbox.

The primary problem I've had with this is that when a parent row checkbox item is checked, the checkboxes of that category's child rows don't get checked until a second checkbox in the grid is checked.  It's like the checkbox checking/unchecking isn't actually performed until another event fires. 

I've tried handling this in rowChanged, valueChanged, CellEndEdit, CellValueChanged, and other events, and they all seem to do what I want in debugging, but the visible checking of child row checkboxes doesn't happen when it should.

I'm opposed to posting any of the code I've tried since I've tried so many approaches and just seem to be going round and round,  but will instead put it in pseudocode format.  So here's what I'm trying to accomplish:

Private Sub gridItems_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles gridItems.ValueChanged

 

 

    'If the changed item is a parent row checkbox Then

 

 

 

        ' For each childRow in currentRow.childRows

 

 

 

            ' childRow.checkboxColumn.checkboxEditor.Value = currentRow.checkboxColumn.checkBoxEditor.Value

 

 

        ' Next

 

 

 

    'End If

 

 

 

 

End Sub

 

 

 

Thank you in advance for any suggestions and advice.
Dan
 

6 Answers, 1 is accepted

Sort by
0
Svett
Telerik team
answered on 16 Mar 2010, 03:44 PM
Hi Daniel Sprague,

Your approach is correct. You need to subscribe to ValueChanged event and use the following code snippet to achieve the desired behavior:
this.radGridView.ValueChanged += new EventHandler(radGridView_ValueChanged);

private void radGridView_ValueChanged(object sender, EventArgs e)
{
    RadCheckBoxEditor editor = sender as RadCheckBoxEditor;
 
    if (editor != null)
    {
        GridViewDataRowInfo dataRow = (GridViewDataRowInfo)this.radGridView.CurrentRow;
        GridViewDataColumn dataColumn = (GridViewDataColumn)this.radGridView.CurrentColumn;
        CheckChildRows(dataRow, (bool)editor.Value);
    }
}
 
private void CheckChildRows(GridViewDataRowInfo dataRow, bool value)
{
    if (dataRow.ChildRow != null)
    {
        GridViewInfo childViewInfo = dataRow.ChildRow.ChildViewInfo;
        foreach (GridViewDataRowInfo childRow in childViewInfo.Rows)
        {
            childRow.Cells["BoolColumn"].Value = value;
            CheckChildRows(childRow, value);
        }
 
        if (childViewInfo.GridViewElement != null)
        {
            childViewInfo.GridViewElement.Update(
            GridUINotifyAction.DataChanged);
        }
    }
}

If you need further assistance, feel free to write back.

Best wishes,
Svett
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
Daniel Sprague
Top achievements
Rank 1
answered on 16 Mar 2010, 03:53 PM
Svett, you're awesome!  Thanks much!!!
0
Sheraz Naseeb
Top achievements
Rank 1
answered on 26 Aug 2010, 11:39 AM
Hi Telerik Team,

I need to achieve the same functionality but unfortunately this same code is not working on my end. I am using Q1 2009.

Any idea why ???

Thanks for your help
0
Jack
Telerik team
answered on 27 Aug 2010, 05:04 PM
Hi Sheraz Naseeb,

This code is specific for Q1 2010 and it can not work for older versions. It will be difficult to address the issue in Q1 2009. I recommend that you try our latest release - Q2 2010 SP1. It contains many new features and addresses a lot of issues. We will be glad to help you with the transition process and we will appreciate your feedback regarding the new version.

In case you have other questions, please write back.

Kind regards, 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
Pete
Top achievements
Rank 1
answered on 27 Jun 2011, 04:33 PM
Hello,
I'm using 2010.2.826.35 and I don't have these methods/extenstions available to me.
Thanks,
Pete
0
Jack
Telerik team
answered on 29 Jun 2011, 01:47 PM
Hello Pete,

Please note that this thread relates to our WinForms controls suite. We do not have a version with number 2010.2.826.35 and that is why I suppose that your question targets another suite, for example our Silverlight controls. If this is not the case, I recommend that you try our latest release - Q1 2011 SP1. If you still experience issues, describe the desired behavior in detail and send us a sample application. This will help us to understand the issue and find a proper solution faster.
 
All the best,
Jack
the Telerik team
Q1’11 SP1 of RadControls for WinForms is available for download; also available is the Q2'11 Roadmap for Telerik Windows Forms controls.
Tags
GridView
Asked by
Daniel Sprague
Top achievements
Rank 1
Answers by
Svett
Telerik team
Daniel Sprague
Top achievements
Rank 1
Sheraz Naseeb
Top achievements
Rank 1
Jack
Telerik team
Pete
Top achievements
Rank 1
Share this question
or