Enable or disable GridSwitchColumn depending on contents row

afbeeldingCursistAanwezigheidSmall.jpg Hello all,
Have build an app where students can confirm that they are present. The datagrid shows a list of lessons the student is attending. The last column is a GridSwitchColumn.
The student can see if he/she was present.
The datagrid is bound to a viewmodel.
This works fine.
What I am not able to build is that a student is only allowed to switch to present in the row of today. Am able to check this condition. But am not able to disable the checkbox for other dates than today. Only after clicking (using event DataGrid_ValueChanged) am I able to mention to the user that it is not allowed but is too late in my perception of user friendlyness.
Have tried 
dataGrid.CurrentCellBeginEdit , dataGrid.CurrentCellActivating but all not fired for gridswitchcolumn.

Any suggestions are welcome. Greetings, Ronald


3 Replies

KK Karthikraja Kalaimani Syncfusion Team September 29, 2021 12:35 PM UTC

Hi Bruno,  

Thank you for contacting Syncfusion support. 

We would like to let you know that, we used Xamarin forms CheckBox in GridSwitchColumn. By writing custom cell renderer for GridSwictchColumn, we can access the IsEnabled property of the CheckBox. Then using the IsEnabled property, we can disable the checkbox. Please refer to the below code snippet and attached sample. 

Code snippets : 
 
 this.dataGrid.CellRenderers.Remove("Switch");
            this.dataGrid.CellRenderers.Add("Switch", new CustomSwitchCellRenderer());
....
 public class CustomSwitchCellRenderer : GridCellSwitchRenderer
 
    { 
        protected override SfSwitchControl OnCreateDisplayUIView() 
        { 
            var switchControl = new SfSwitchControl(); 
            switchControl.PropertyChanged += SwitchControl_PropertyChanged; 
            return switchControl; 
        } 
  
        private void SwitchControl_PropertyChanged(object sender, PropertyChangedEventArgs e) 
        { 
            if (e.PropertyName == "Parent") 
            { 
                if ((((sender as SfSwitchControl).Parent as GridCell).DataColumn.RowData as Data).No_1 == 11) 
                { 
                    (sender as SfSwitchControl).IsEnabled = false; 
                } 
            } 
        } 
    } 
  
Sample link : https://www.syncfusion.com/downloads/support/directtrac/general/ze/DataGridDemo555066912.zip

We hope this helps, please let us know if you need further assistance from us. 

Regards,
Karthik Raja
 



RO Ronald September 29, 2021 04:05 PM UTC

Good evening,

Thanks a lot!

This works just I had asked.

Was busy with different methods but this works best.

Greetings

Ronald



LN Lakshmi Natarajan Syncfusion Team September 30, 2021 04:02 AM UTC

Hi Ronald, 
 
Thank you for the update. 
 
We are glad that our solution meets your requirement. Please let us know if you need further assistance. As always, we are happy to help you out. 
 
Lakshmi Natarajan 
 


Loader.
Up arrow icon