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

Change CheckBox Cell Value

4 Answers 62 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Scott Michetti
Top achievements
Rank 1
Scott Michetti asked on 06 Oct 2011, 09:33 PM
Hello, I'm defining a checkbox column in xaml.

<

 

 

telerikGridView:GridViewDataColumn DataMemberBinding="{Binding Select}" Header=" ">

 

 

 

 

<telerikGridView:GridViewDataColumn.CellTemplate>

 

 

 

 

<DataTemplate>

 

 

 

 

<CheckBox HorizontalAlignment="Center" Click="checkBox_Click" IsThreeState="False" Loaded="chk_Loaded" />

 

 

 

 

</DataTemplate>

 

 

 

 

</telerikGridView:GridViewDataColumn.CellTemplate>

 

 

 

 

</telerikGridView:GridViewDataColumn>

 

I would like to check or uncheck the checkboxes through code. How would I do this? Something like:
CheckBox c = myGrid.Columns[0].Cells[3].Control as CheckBox;
I know that in the click event I can grab the checkbox by using the following code, but that doesn't help me out when I want to change values without the click event.
Thanks
Scott

CheckBox

 

 

checkBox = e.OriginalSource as CheckBox;

 

 

 

GridViewCell parentCell = checkBox.ParentOfType<GridViewCell>();

 

4 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 07 Oct 2011, 06:36 AM
Hi Scott Michetti,

I would recommend you to bind the IsChecked property of the CheckBox to the underlying property - I believe in your case it should be "Select". Thus, you will be able to update directly the property for the item you want and the CheckBox will be checked/unchecked accordingly.
 

All the best,
Maya
the Telerik team

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

0
Vlad
Telerik team
answered on 07 Oct 2011, 06:40 AM
Hello,

 Working with events in UI virtual controls like DataGrid, ListBox, RadGridView, etc is not recommended. Such components does not have collections of UI elements like rows, cells, etc. since the virtualization will recycle the UI containers and will reuse them with different data context. 

Please bind your IsChecked property to your view model - MVVM is the recommended approach. 

Greetings,
Vlad
the Telerik team

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

0
Scott Michetti
Top achievements
Rank 1
answered on 07 Oct 2011, 03:32 PM
Thanks Maya and Vlad. I removed the events and now bind the IsChecked property. If I add the INotifyPropertyChanged to the class I'm binding to, it works. One last question. Under this scenario, is it possible to add a checkbox at the top of the column that will check or uncheck all checkboxes in the column? I've seen samples of a checkbox in the header, but it only allows row selection.
Thanks again for your help.

Scott
0
Vanya Pavlova
Telerik team
answered on 07 Oct 2011, 03:39 PM
Hi Scott Michetti,

 

You may predefine the Header property of a column, place the CheckBox control and within its Checked event handler you may implement the logic you need, please refer to the following forum thread. 
This is just an example feel free to change it in the way you need. 



Kind regards,
Vanya Pavlova
the Telerik team

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

Tags
GridView
Asked by
Scott Michetti
Top achievements
Rank 1
Answers by
Maya
Telerik team
Vlad
Telerik team
Scott Michetti
Top achievements
Rank 1
Vanya Pavlova
Telerik team
Share this question
or