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
4 Answers, 1 is accepted
0
PW
Top achievements
Rank 1
answered on 03 Sep 2009, 09:10 PM
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
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
0
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.
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.
0
Scott Michetti
Top achievements
Rank 1
answered on 27 Sep 2011, 09:12 PM
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>
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>
0
Edward Pauley
Top achievements
Rank 1
answered on 27 Sep 2011, 10:44 PM
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>
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>