WPftoolkit : ccheckbox

Apr 8, 2009 at 11:39 AM
Hi
I have a wpftoolkit checkbox control in my grid, Everytime there is a check or an uncheck I want to call a method, how do I attain this?

Regards
Bharti
Coordinator
Apr 8, 2009 at 11:41 PM
Edited Apr 8, 2009 at 11:42 PM
Hi Bharti,

It doesn't look like we expose the Checked and Unchecked events on DataGridCheckBoxColumn, so I would recommend trying a DataGridTemplateColumn with a CheckBox in the CellTemplate, like so:

<DataGrid>

 

 <DataGrid.Columns>

 

 

 

   <DataGridTemplateColumn>

 

 

 

     <DataGridTemplateColumn.CellTemplate>

 

 

 

       <DataTemplate>

 

 

         <CheckBox Checked="CheckBox_Checked"/>

 

 

        </DataTemplate>

 

 

     </DataGridTemplateColumn.CellTemplate>

 

 

   </DataGridTemplateColumn>

 

 

  </DataGrid.Columns>

 

 

</DataGrid>

 

 

 

Apr 9, 2009 at 11:05 AM

Hi Samanth
I did as suggested as below:

<toolkit:DataGrid.Columns>                   

                    <toolkit:DataGridTextColumn     Binding="{Binding Path=TimeOfValidity,  Mode=OneWay}" IsReadOnly="True"  Width="170"/>              

<o:p> </o:p>

<o:p> </o:p>

                    <toolkit:DataGridTemplateColumn >

                        <toolkit:DataGridTemplateColumn.CellTemplate>

                            <DataTemplate>

                                <CheckBox Checked="CheckBox_Checked" Unchecked="CheckBox_Checked"/>                               

                            </DataTemplate>

                        </toolkit:DataGridTemplateColumn.CellTemplate>

                    </toolkit:DataGridTemplateColumn>

<o:p> </o:p>

<o:p> </o:p>

                    <toolkit:DataGridTextColumn     Binding="{Binding Path=Range,           Mode=OneWay}" IsReadOnly="True"  Width="50"/>

<o:p> </o:p>

By doing this it fired on both check and uncheck, but then how do I bind this to      Binding="{Binding Path=Used}"

<o:p>I need this because I get my initial values in th egrid from database. </o:p>

<o:p> </o:p>

<o:p> </o:p>

<o:p> </o:p>

My actual code at the moment looks like:

<o:p> </o:p>

</toolkit:DataGrid.Resources>               

<o:p> </o:p>

                    <toolkit:DataGridTextColumn     Binding="{Binding Path=TimeOfValidity,  Mode=OneWay}" IsReadOnly="True"  Width="170"/>

               

                    <toolkit:DataGridCheckBoxColumn Binding="{Binding Path=Used}"                                            Width="SizeToHeader">                                         

                                                

                    </toolkit:DataGridCheckBoxColumn>

                    <toolkit:DataGridTextColumn     Binding="{Binding Path=Range,           Mode=OneWay}" IsReadOnly="True"  Width="50"/>

<o:p> </o:p>

Thanks and Regards

Bharti

<o:p> </o:p>

Coordinator
Apr 9, 2009 at 5:15 PM
Hi Bharti,

I think you want to bind the IsChecked property of your CheckBox to the Used field, like this:

<toolkit:DataGrid.Columns>                   

    <toolkit:DataGridTextColumn     Binding="{Binding Path=TimeOfValidity, Mode=OneWay}" IsReadOnly="True"  Width="170"/>              

    <toolkit:DataGridTemplateColumn >

        <toolkit:DataGridTemplateColumn.CellTemplate>

            <DataTemplate>

                <CheckBox Checked="CheckBox_Checked" Unchecked="CheckBox_Checked" 
                          IsChecked="{Binding Path=Used}"/>                               

            </DataTemplate>

        </toolkit:DataGridTemplateColumn.CellTemplate>

    </toolkit:DataGridTemplateColumn>

    <toolkit:DataGridTextColumn Binding="{Binding Path=Range, Mode=OneWay}" IsReadOnly="True"  Width="50"/>