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

7 posts, 0 answers
  1. Daniel Sprague
    Daniel Sprague avatar
    17 posts
    Member since:
    Feb 2010

    Posted 12 Mar 2010 Link to this post

    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
     

  2. Svett
    Admin
    Svett avatar
    728 posts

    Posted 16 Mar 2010 Link to this post

    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.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Daniel Sprague
    Daniel Sprague avatar
    17 posts
    Member since:
    Feb 2010

    Posted 16 Mar 2010 Link to this post

    Svett, you're awesome!  Thanks much!!!
  5. Sheraz Naseeb
    Sheraz Naseeb avatar
    22 posts
    Member since:
    Mar 2010

    Posted 26 Aug 2010 Link to this post

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

    Posted 27 Aug 2010 Link to this post

    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
  7. Pete
    Pete avatar
    14 posts
    Member since:
    Jun 2010

    Posted 27 Jun 2011 Link to this post

    Hello,
    I'm using 2010.2.826.35 and I don't have these methods/extenstions available to me.
    Thanks,
    Pete
  8. Jack
    Admin
    Jack avatar
    2335 posts

    Posted 29 Jun 2011 Link to this post

    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.
Back to Top
UI for WinForms is Visual Studio 2017 Ready