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

SelectAll method giving error in HeaderCellToggleStateChanged

1 Answer 134 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Lokesh
Top achievements
Rank 1
Lokesh asked on 14 May 2015, 09:48 AM

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

1 Answer, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 18 May 2015, 02:31 PM
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
Tags
GridView
Asked by
Lokesh
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or