Change CheckBox Cell Value

5 posts, 0 answers
  1. Scott Michetti
    Scott Michetti avatar
    97 posts
    Member since:
    Feb 2010

    Posted 06 Oct 2011 Link to this post

    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>();

     

  2. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 07 Oct 2011 Link to this post

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

  3. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 07 Oct 2011 Link to this post

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

  4. Scott Michetti
    Scott Michetti avatar
    97 posts
    Member since:
    Feb 2010

    Posted 07 Oct 2011 Link to this post

    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
  5. Vanya Pavlova
    Admin
    Vanya Pavlova avatar
    2019 posts

    Posted 07 Oct 2011 Link to this post

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

Back to Top