Problem checking all checkboxes in RadGridView

5 posts, 0 answers
  1. christine
    christine avatar
    17 posts
    Member since:
    Jul 2010

    Posted 03 Oct 2011 Link to this post

    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++;
            }
        }
    }

  2. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 04 Oct 2011 Link to this post

    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 >>

  3. Shiva
    Shiva avatar
    61 posts
    Member since:
    Oct 2010

    Posted 31 Oct 2011 Link to this post

    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
  4. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 31 Oct 2011 Link to this post

    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 >>

  5. Shiva
    Shiva avatar
    61 posts
    Member since:
    Oct 2010

    Posted 31 Oct 2011 Link to this post

    And it worked....Thank u so much..:)
Back to Top