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

Problem checking all checkboxes in RadGridView

4 Answers 87 Views
GridView
This is a migrated thread and some comments may be shown as answers.
christine
Top achievements
Rank 1
christine asked on 03 Oct 2011, 10:00 PM

I have a radGridView with a checkbox column.  When a button is clicked I want to automatically check all of the checkboxes in that column of the RadGridView.  I am using the following example code, the problem is that this code only checks VIEWABLE checkboxes, so if I scroll down in the grid the remaining checkboxes are unchecked.  I am trying to find a way to check all checkboxes in that column (not just the viewable ones).  Thanks in advance for any help!

<telerik:GridViewColumn Header="Voucher" >
    <telerik:GridViewColumn.CellTemplate>
        <DataTemplate>
            <CheckBox IsChecked="{Binding VoucherRequested}" Width="75" />
        </DataTemplate>
    </telerik:GridViewColumn.CellTemplate>
</telerik:GridViewColumn>

IList<GridViewRow> rows = RadGridView_TrusteeLedgers.ChildrenOfType<GridViewRow>();
int checkboxCount = 0;
foreach (GridViewRow row in rows)
{
    if (!(row is GridViewNewRow) && !(row is GridViewHeaderRow))
    {
        Ledger_Get6855TTPendingLedgers_Result result = row.DataContext as Ledger_Get6855TTPendingLedgers_Result;
 
        CheckBox checkBox = row.Cells[9].ChildrenOfType<CheckBox>().FirstOrDefault();
        if (checkBox != null)
        {
            if (CheckBox_VoucherListedItems.IsChecked == true)
            {
                checkBox.IsChecked = true;
            }
            else
            {
                checkBox.IsChecked = false;
            }
            checkboxCount++;
        }
    }
}

4 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 04 Oct 2011, 06:46 AM
Hello Christine,

It is not recommended to work with the visual elements and their properties - as it is in your case with GridViewCell-s, the CheckBox-es inside and their IsChecked property. The virtualization of the grid is turned on by default which means that once you scroll, all visible elements will be recycled and reused. 
What you should do is work with the data item and set the VouncherRequested property of each of the items (using Items collection of the grid) to "True".

All the best,
Maya
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Shiva
Top achievements
Rank 1
answered on 31 Oct 2011, 11:32 AM
Dear Maya,

I'm undergoing same through same problem. Can you please urgently provide me some code snippet of the same.

Its urgent.

Thank you,
Shiva
0
Maya
Telerik team
answered on 31 Oct 2011, 12:34 PM
Hello Shiva,

The idea is to work with the underlying data item and update the corresponding property. So, if you have a column defined like:

<telerik:GridViewCheckBoxColumn DataMemberBinding="{Binding IsPlaying}" />

You can update the property IsPlaying like:
private void RadButton_Click(object sender, RoutedEventArgs e)
        {
            foreach(Player player in this.playersGrid.Items)
            {
                player.IsPlaying = false;
            }
        }

 

Best wishes,
Maya
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Shiva
Top achievements
Rank 1
answered on 31 Oct 2011, 12:54 PM
And it worked....Thank u so much..:)
Tags
GridView
Asked by
christine
Top achievements
Rank 1
Answers by
Maya
Telerik team
Shiva
Top achievements
Rank 1
Share this question
or