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

Radgridview with CheckBox - CheckAll and UnCheckAll

1 Answer 146 Views
GridView
This is a migrated thread and some comments may be shown as answers.
muralitharan
Top achievements
Rank 1
muralitharan asked on 02 Feb 2010, 11:37 AM
Hi,

We are using Radgridview with CheckBox and also we have added the CheckAll and UnCheckAll button. We have finished this CheckAll and UnCheckAll functionalities using looping with grid.rows.count, but when we are filter the row it shows the total rows count and also getting the exception like 'Index 145 is either negative or above rows count.'. Refer the below code and kindly let me know how we have to solve this issue.

CheckAll:

for

 

(int i = 0; i < radGrid.Rows.Count; i++)

 

 

 {

    radGrid.Rows[i].Cells[

"-"].Value = Boolean.TrueString;

 

 

     item = radGrid.Rows[i].DataBoundItem;

 

    if (!this.selectedRows.Contains(item))

 

 

 

        this.selectedRows.Add(item);

 

 

 }

 

UnCheckAll:

this

 

.selectedRows.Clear();

 

 

 

for (int i = 0; i < radGrid.Rows.Count; i++)

 

 

 {

         radGrid.Rows[i].Cells[

"-"].Value = Boolean.FalseString;

 

 

 }

 



Regards,
Murali.S


1 Answer, 1 is accepted

Sort by
0
Nick
Telerik team
answered on 02 Feb 2010, 12:09 PM
Hi muralitharan,

Thank you for contacting us. Here is a better version of SelectAll method:

private void button1_Click(object sender, EventArgs e)
{
       myGrid.MultiSelect = true;
       myGrid.GridElement.BeginUpdate();
              
       foreach (DataRow row in ((DataTable)this.myGrid.DataSource).Rows)
       {
           row["B"] = true;
       }
  
       foreach (GridViewRowInfo info in this.myGrid.Rows)
       {
           info.IsSelected = true;
       }
              
       myGrid.GridElement.EndUpdate();
}

The UnselectAll is almost the same. You need to use BeginUpdate/EndUpdate to increase the performace e.g. batch operation. Do not hesitate to write me back if you have further question.

Kind regards,
Nick
the Telerik team

Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Follow the status of features or bugs in PITS and vote for them to affect their priority.
Tags
GridView
Asked by
muralitharan
Top achievements
Rank 1
Answers by
Nick
Telerik team
Share this question
or