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

GridCheckBoxColumn dont raise RowValidating / RowValidated events

Hi Syncfusion Team

Alls columns type, like ComboBox and Text, raise RowValidating / RowValidated events when user move to other row in grid, except GridCheckBoxColumn.

Scenario:
WPF .Net 4.6.1, sfDataGrid 13.3.0.18 Community Edition, ItemsSource = ObservableCollection, GridValidationMode = InEdit, EditTrigger = OnTap, NavigationMode = Cell, SelectionMode = Extended

Steps:
- User enter in any text column, sfDataGrid raise CellBeginEdit event
- User change value, raise multiple CellValueChanged events
- User move to another row, raising CellValidating, CellValidated, RowValidating, RowValidated and CellEndEdit events

In RowValidated I can save changes in SQLite database.

- User click in checkbox column, sfDataGrid raise CellValueChanged event
- User move to another row (click in RowHeader or click in checkbox in other row) and sfDataGrid dont raise RowValidating / RowValidated

My ugly turn around:

 - SelectionMode = Single
 - private bool anyChanges = false in window scope;
 - anyChanges = true in CurrentCellDropDownSelectionChanged and CurrentCellValueChanged events;
 - if(anyChanges) {...} in SelectionChanging event to save changes in SQLite database


Sorry my poor english, and hugs from Brasil.

Marcio Maciel


5 Replies

JG Jai Ganesh S Syncfusion Team December 28, 2015 11:44 AM UTC

Hi Marcio,


Thank you for using Syncfusion Products.


We regret to inform you that, the Events like BeginEdit, EndEdit, CellValidating and RowValidating will not be triggered for GridCheckBoxColumn in SfDataGrid. In GridCheckBoxColumn, we loaded the EditElement directly hence the above events are not supported in GridCheckBoxColumn. However we have prepared the work around for firing the Validated event like the below code example,


Code Example[C#]:



 
void DataGrid_CurrentCellValueChanged(object sender, CurrentCellValueChangedEventArgs args)
        {

            int rowIndex = args.RowColumnIndex.RowIndex;
            int columnIndex =this.DataGrid.ResolveToGridVisibleColumnIndex(args.RowColumnIndex.ColumnIndex);

            //We are enabling the RowValidating event if the changes happen in GridCheckBoxColumn
            if (this.DataGrid.Columns[columnIndex].CellType == "CheckBox")
            {
                this.DataGrid.GetValidationHelper().SetCurrentRowValidated(false);
            }
     
        }
 


Here we have setting the IsCurrentRowValidated as false using ValidationHelper.SetCurrentRowValidated()
method.



Sample Location: http://www.syncfusion.com/downloads/support/directtrac/148928/ze/ValidateTestSfGrid201200701

 
Please let me know if you have any other concerns.


Regards,
Jai Ganesh S




DS dsfakjhasdfkbn March 2, 2016 01:24 PM UTC

Hi

I could not use this workaround (manually calling SetCurrentRowValidated(false)) because the event DataGrid_CurrentCellValueChanged does not fire for GridComboBoxColumn and also not for a ComboBoxAdv in a DataTemplate.
My environment is slightly different: WPF .Net 4.5.1, sfDataGrid  13.4451.0.58, 13.4.0.58 Community Edition

I attached a sample solution derived from your works (zip file provided by Jai Ganesh S, see below)
Could please someone look into this? Thanks.



Attachment: ValidateTestSfGrid201200701with_CheckBoxAndComboBoxAdv_e6868e84.zip


SV Srinivasan Vasu Syncfusion Team March 4, 2016 04:02 AM UTC

Hi Marcio,


We regret to inform you that, the CurrentCellValueChanged event will not be trigger for GridComboxBoxColumn and GridTemplateColumn in SfDataGrid.  For GridComboBoxColumn, you have to use CurrentCellDropDownSelectionChanged event for notify the value changes and for GridTemplateColumn you have to use separate event as per the control that you have loaded in it. For an example, you have loaded the ComboBoxAdv control where you have you can use SelectionChanged event to notify the selection changed. Please refer the below code example,


C#



GridComboBoxColumn
:

using Syncfusion.UI.Xaml.Grid.Helpers;


void DataGrid_CurrentCellDropDownSelectionChanged(object sender, CurrentCellDropDownSelectionChangedEventArgs args)

        {

            int rowIndex = args.RowColumnIndex.RowIndex;

            int columnIndex = this.DataGrid.ResolveToGridVisibleColumnIndex(args.RowColumnIndex.ColumnIndex);

           //We are enabling the RowValidating event if the changes happen in GridCheckBoxColumn

            if (this.DataGrid.Columns[columnIndex].CellType == "ComboxBox")

            {

                this.DataGrid.GetValidationHelper().SetCurrentRowValidated(false);

            }       

        }          




GridCheckBoxColumn
:

using Syncfusion.UI.Xaml.Grid.Helpers;


void DataGrid_CurrentCellValueChanged(object sender, CurrentCellValueChangedEventArgs args)

        {

int rowIndex = args.RowColumnIndex.RowIndex;

            int columnIndex = this.DataGrid.ResolveToGridVisibleColumnIndex(args.RowColumnIndex.ColumnIndex);          

            //We are enabling the RowValidating event if the changes happen in GridCheckBoxColumn

            if (this.DataGrid.Columns[columnIndex].CellType == "CheckBox")

            {

                this.DataGrid.GetValidationHelper().SetCurrentRowValidated(false);

            }        

}



ComboxAdv
in GridTemplateColumn:

  using Syncfusion.UI.Xaml.Grid.Helpers;


  private void MyComboBox_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)

        {                   

                this.DataGrid.GetValidationHelper().SetCurrentRowValidated(false);              

        }            





We have prepared a sample as per your requirement and you can download the same from the below location,


Sample : http://www.syncfusion.com/downloads/support/forum/121528/ze/ValidateTest329851855



Regards,

Srinivasan



DS dsfakjhasdfkbn March 7, 2016 05:08 PM UTC

Hi Vasu

Thank you very much for the update. With these workarounds RowValidating will be fired for all in this thread mentioned controls.
In the zip, the file MainWindow.xaml.cs has a typo "ComboxBox" instead of "ComboBox".

Thanks again


SV Srinivasan Vasu Syncfusion Team March 8, 2016 11:28 AM UTC

Hi Marcio,

Sorry for the inconvenience

We have corrected the mistake “ComboxBox” instead of “ComboBox”. We have attached modified sample. Please find the sample from the below location.

Sample:
http://www.syncfusion.com/downloads/support/forum/121528/ze/ValidateTest-911450465
Regards,
Srinivasan
 



Loader.
Live Chat Icon For mobile
Up arrow icon