Loop through Records / Check All checkboxes

5 posts, 0 answers
  1. Casey
    Casey avatar
    27 posts
    Member since:
    May 2009

    Posted 03 Sep 2009 Link to this post

    For my Telerik Datagrid, each row has a first column with a checkbox.

    I need a 'Check All' button at the top. I thought this was working, but i got off on other stuff, and now I can't get it working.. please help.

    obviously it is preferable if i only check the first column.

     

     

     

     

     

    foreach (DataRecord r in dataGrid.Records)

     

    {

     

        string s = r.Data.ToString();

     

     

        if (r.Data is CheckBox)

     

            {

     

                CheckBox cb = (CheckBox)r.Data;

     

                cb.IsChecked =

    true;

     

            }

    }

    Casey

  2. PW
    PW avatar
    13 posts
    Member since:
    May 2009

    Posted 03 Sep 2009 Link to this post

    I am struggling with the same type of issue.

    I want a button in which I can select or deselect the checkboxes in the first column of my grid. My biggest issue with this is that I don't seem to have a way to say something like for each row in the grid take the checkbox in the first cell and either check or uncheck it.

    Is there anyone out there that can help?

    Thanks

  3. Milan
    Admin
    Milan avatar
    1989 posts

    Posted 04 Sep 2009 Link to this post

    Hello,

    Probably the best approach to do that is to introduce a property called IsChecked on your data items and bind the CheckBox column to that property. When you want to check all or uncheck all just loop through all data items and set their IsChecked property to true or false which will utimately update all checkboxes as well.

    I have prepared a sample application that demonstrates this approach.

    Kind regards,
    Milan
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  4. Scott Michetti
    Scott Michetti avatar
    97 posts
    Member since:
    Feb 2010

    Posted 27 Sep 2011 Link to this post

    Hello. I tried your attached sample and added a CellTemplate to the "Checked" column. This is what I do in my own project. But when I loop through, the checkboxes don't change. If I remove the GridViewDataColumn.CellTemplate Xaml, it will work again. How can I get this to work using the cell template?

    Thanks
    Scott Michetti

    <telerik:GridViewDataColumn Header="Checked" DataMemberBinding="{Binding IsChecked, Mode=TwoWay}">
                        <telerik:GridViewDataColumn.CellTemplate>
                            <DataTemplate>
                                <CheckBox HorizontalAlignment="Center" IsThreeState="False" Loaded="chk_Loaded" Click="checkBox_Click"/>
                            </DataTemplate>
                        </telerik:GridViewDataColumn.CellTemplate>
                    </telerik:GridViewDataColumn>
  5. Edward Pauley
    Edward Pauley avatar
    49 posts
    Member since:
    May 2010

    Posted 27 Sep 2011 Link to this post

    Hi scott,

    i have just looked at your xaml. I think you are missing the binding for the cellTemplate part
    it should be something similar like this

    <telerik:GridViewDataColumn Header="Checked" DataMemberBinding="{Binding IsChecked, Mode=TwoWay}">
                        <telerik:GridViewDataColumn.CellTemplate>
                            <DataTemplate>
                                <CheckBox IsChecked="{Binding IsChecked,Mode=TwoWay}" HorizontalAlignment="Center" IsThreeState="False" Loaded="chk_Loaded" Click="checkBox_Click"/>
                            </DataTemplate>
                        </telerik:GridViewDataColumn.CellTemplate>
                    </telerik:GridViewDataColumn>

Back to Top