CurrentCellBeginEdit event is not triggered when I click GridSwitchColumn

Hi, 
Im using GridSwitchColumn for my SfDataGrid, and what I want is when I click that  GridSwitchColumn before the value change, i want to check first if some data is true or note, if true, I want to cancel editing. Or in short, is disable editing in some row & column based on some value of the data.

but the problem is when i use  CurrentCellBeginEdit event, its doesn't trigerred. help me please. Thanks

here is my code:

public KonfirmasiBarangRepairStep2()

{

            InitializeComponent();

            viewModel = BindingContext as KonfirmasiBarangRepairStep2ViewModel;

            viewModel.InitPage = true;

            barangRepariGrid.CurrentCellBeginEdit += barangRepariGrid_CurrentCellBeginEdit;

}


private void barangRepariGrid_CurrentCellBeginEdit(object sender, Syncfusion.SfDataGrid.XForms.GridCurrentCellBeginEditEventArgs e)

        {

            int rowIndex = this.barangRepariGrid.ResolveToRecordIndex(e.RowColumnIndex.RowIndex);

            var record = this.barangRepariGrid.View.Records[rowIndex];

            if ((record.Data as T_REPAIR_DET).KONFIRMASI_F_B_O == true)

            {

                (record.Data as T_REPAIR_DET).KONFIRMASI_F_B = true;

                e.Cancel = true;

            }

        }


1 Reply

LN Lakshmi Natarajan Syncfusion Team April 20, 2022 04:46 AM UTC

Hi Galih,


The CurrentCellBeginEdit event is not triggered for the GridSwitchColumn because the switch is used to change its states, which is not editing. You can also achieve your goal by using the GridTemplateColumn and loading the SfSwitch into the CellTemplate. The SfSwitch allows you to cancel moving to a new state by using the StateChanging event.


Please refer to our user guidance document regarding SfSwitch,

UG link: https://help.syncfusion.com/xamarin/switch/gettingstarted#performing-an-action-based-on-state


Please refer to the following code snippets for more reference,

//XAML

 

<sfgrid:GridTemplateColumn MappingName="IsChecked">

    <sfgrid:GridTemplateColumn.CellTemplate>

        <DataTemplate>

            <buttons:SfSwitch IsOn="{Binding IsChecked, Mode=TwoWay}"

                        StateChanging="SfSwitch_StateChanging"/>

        </DataTemplate>

    </sfgrid:GridTemplateColumn.CellTemplate>

</sfgrid:GridTemplateColumn>

 

//Code behind

 

private void SfSwitch_StateChanging(object sender, Syncfusion.XForms.Buttons.SwitchStateChangingEventArgs e)

{

    if (...) // Your condition

    {

        e.Cancel = true;

    }

}


Please refer to our user guidance regarding GridTemplateColumn in the following link,

UG link: https://help.syncfusion.com/xamarin/datagrid/column-types#gridtemplatecolumn


Please let us know if you need further assistance.


Regards,

Lakshmi Natarajan


Loader.
Up arrow icon