Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
3305
how do you trap a checkbox "checked/Unchecked" event in the grid?
posted

I see no CellUpdated event in the XamWebGrids event model. I need to be able to trap a checkbox  value in a boolean column when taht value  is changing. The data source is a dynamic Idictioanry so I can't trap a property changed event, because there is none.

 

Parents
No Data
Reply
  • 40030
    Offline posted

    Hi, 

    Hmm, so this is a trickier issue, as my first solution would be to use your ViewModel and my second would have been to use our editing events. 

    However, from what you described, it sounds like you have to be using a TemplateColumn. So first, i would suggest hooking up the Checked/Unchecked events of the Checkbox in that column. 

    <DataTemplate>
    <CheckBox Checked="CB_Checked", Unchecked="CB_Unchecked" />

    </DataTemplate>

    This would do the trick, however, if you're creating the templates via a XamlReader, then that of course won't work. 

    Which means that your only other choice would be to use the CellControlAttached event, and hook/unhook the events there. 

    something like: 

    if(e.Cell.Column.Key == "MyCBCol")
    {

           CheckBox cb = e.Cell.Control.Content as CheckBox;

           if(cb != null)

           {

               cb.Checked -= CB_Checked;

               cb.Checked += CB_Checked

          }

    }

     Its important that you remove the eventhandler before you attach it, otherwise you'll wind up hooking the event up multiple times, as cells get recycled. 

    Also, make sure you are using the latest Service Release, as there used to be an issue, where the content of a TemplateColumn, wouldn't be set during the firing of this event. 

    Hope this helps, 

    -SteveZ

     

Children