We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

How to trigger CurrentCellBeginEdit for Checkbox column

GridTemplateColumn is dynamically added to SfDataGrid . This GridTemplateColumn.CellTemplate is bound to Checkbox control. My data is bound to this SfDataGrid. This grid has few more columns too.

On Editing other columns CurrentCellBeginEdit triggers. But on check/uncheck of this checkbox column, this event doesnt fire.

Tried associating a 'Click' event to the the checkbox and also 'CurrentCellValueChanged' event to the SfDataGrid. No luck.




5 Replies 1 reply marked as answer

DM Dhanasekar Mohanraj Syncfusion Team February 28, 2023 02:35 PM UTC

Hi Priya,


You are using the CheckBoc as a CellTemplate element in the GridTemplateColumn. In this case, the Editing related events (CurrentCellValueChanged, CurrentCellBeginEdit) do not get the notifications and are raised. If you need to raise these events for your scenario, then you should use EditTemplate. Our SfDataGrid has the In-built GridCheckBoxColumn. With this, you can get a notification while changing the checkbox value by using the CurrentCellValueChanged event. For more information related to GridCheckBoxColumn, please refer to the below user guide documentation link,

UG Link: https://help.syncfusion.com/wpf/datagrid/column-types#gridcheckboxcolumn


For more information related to the CurrentCellValueChanged event, please refer to the below knowledge base documentation link,


KB Link: https://www.syncfusion.com/kb/6705/how-to-use-the-editing-related-events-in-gridcheckboxcolumn-of-wpf-datagrid-sfdatagrid


Regards,

Dhanasekar M.

If this post is helpful, please consider Accepting it as the solution so that other members can locate it more quickly.



PR priya March 1, 2023 02:12 PM UTC

Thanks for the response.

My requirement restrict to use only 'GridTemplateColumn'. 

defined the below datatemplate in xaml file.

 <DataTemplate x:Key="chkTest">

            <CheckBox IsChecked="{Binding Path=Test, Mode=TwoWay}" HorizontalAlignment="Center"

                      VerticalAlignment="Center" IsEnabled="True"></CheckBox>

</DataTemplate>


Below code is associated to AutoGeneratingColumn method.

GridTemplateColumn checkBoxControl = new GridTemplateColumn();

 checkBoxControl.EditTemplate = Resources["chkTest"] as DataTemplate;

 checkBoxControl.MappingName = "Test";

 checkBoxControl.HeaderText = "Test";

 checkBoxControl.ColumnSizer = GridLengthUnitType.None;

dgMain.RefreshColumns();

e.Column = checkBoxControl;


After changing CellTemplate to EditTemplate,it triggers the change event . But now onload, i dont see the checkbox itself in the column. After i doubleclick(edit mode)i can see the checkbox with checked/unchecked according the DB and also allows edit.

Why is the checkbox(with DB bindings) not visible on the grid load.Currently it displays this column with blank data until its editt



DM Dhanasekar Mohanraj Syncfusion Team March 2, 2023 01:57 PM UTC

Hi Priya,

We regret the inconvenience caused,

You have used the EditTemplate alone that’s why the CellElement does not show in the initial loading. You can overcome this by using the CellTemplate and the EditTemplate shown below,

XAML:

<!-- Here you can define the cell template as not editable using CheckBox's IsEnabled as false. -->
<DataTemplate x:Key="cellTemplate">

    <CheckBox IsEnabled="False" HorizontalAlignment="Center"

              VerticalAlignment="Center" IsChecked="{Binding Path=Status , Mode=TwoWay}" />

</DataTemplate>

<DataTemplate x:Key="editTemplate">

    <CheckBox  HorizontalAlignment="Center"

              VerticalAlignment="Center" IsChecked="{Binding Path=Status , Mode=TwoWay}" />

</DataTemplate>


C#:

this.datagrid.AutoGeneratingColumn += datagrid_AutoGeneratingColumn;

 

private void datagrid_AutoGeneratingColumn(object sender, AutoGeneratingColumnArgs e)

{

    if (e.Column.MappingName == "Status")

    {

        if (e.Column is GridCheckBoxColumn)

        {

            e.Column = new GridTemplateColumn() { MappingName = "Status", HeaderText = "Status" , CellTemplate = App.Current.Resources["cellTemplate"] as DataTemplate , EditTemplate = App.Current.Resources["editTemplate"] as DataTemplate };

        }

    }

}


For more information related to changing the column type, please refer to the below user guide documentation link,

UG Link: https://help.syncfusion.com/wpf/datagrid/columns#changing-column-type

If this post is helpful, please consider Accepting it as the solution so that other members can locate it more quickly.


Marked as answer

PR priya March 3, 2023 05:10 AM UTC

Hi  Dhanasekar ,

thanks....it worked....:)



DM Dhanasekar Mohanraj Syncfusion Team March 3, 2023 01:55 PM UTC

Priya,


We are glad to know that the reported problem has been resolved at your end. Please let us know if you have any further queries on this. We are happy to help.


Loader.
Live Chat Icon For mobile
Up arrow icon