SelectAll method giving error in HeaderCellToggleStateChanged

2 posts, 0 answers
  1. Lokesh
    Lokesh avatar
    7 posts
    Member since:
    Jan 2012

    Posted 14 May 2015 Link to this post

    I am using a Q1 2015 Winforms RadGrid, added a checkbox column, made EnabledHeaderCheckbox = true, added following event and now want to select all rows in the grid when header checkbox is checked, but it is giving object reference error. Here is the code examples - 

     

            private void _sampleRadGridView_HeaderCellToggleStateChanged(object sender, GridViewHeaderCellEventArgs e)
            {
                if (e.State.ToString() == "On")
                        _sampleRadGridView.SelectAll();
                else
                    _sampleRadGridView.ClearSelection();

             }

    Please help. Thanks

  2. Dess
    Admin
    Dess avatar
    1601 posts

    Posted 18 May 2015 Link to this post

    Hello Lokesh,

    Thank you for writing.

    I confirm that it is an issue with RadGridView. I have logged it in our feedback portal. You can track its progress, subscribe for status changes and add your vote/comment to it on the following link - feedback item.

    I have also updated your Telerik points.

    Currently, the possible solution that I can suggest is to select manually each row without Begin/EndUpdate block which will refresh the whole grid:
    private void radGridView1_HeaderCellToggleStateChanged(object sender, GridViewHeaderCellEventArgs e)
    {
        bool selected = e.State.ToString() == "On";
     
        foreach (GridViewRowInfo r in this.radGridView1.Rows)
        {
            r.IsSelected = selected;
        }
    }

    An alternative solution is to use the MouseUp event:
    private void radGridView1_MouseUp(object sender, MouseEventArgs e)
    {
        RadCheckBoxElement el = this.radGridView1.ElementTree.GetElementAtPoint(e.Location) as RadCheckBoxElement;
        if (el!=null)
        {
            GridCheckBoxHeaderCellElement headerCell = el.Parent as GridCheckBoxHeaderCellElement;
            bool selected = el.ToggleState == Telerik.WinControls.Enumerations.ToggleState.On;
            if (headerCell!=null)
            {
                if (selected)
                {
                    this.radGridView1.SelectAll();
                }
                else
                {
                    this.radGridView1.ClearSelection();
                }
            }
        }
    }

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