- Home
- Forum
- Xamarin.Forms
- Enable or disable GridSwitchColumn depending on contents row
Enable or disable GridSwitchColumn depending on contents row
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
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; } } } } |
We hope this helps, please let us know if you need further assistance from us.
Regards,
Karthik Raja
Good evening,
Thanks a lot!
This works just I had asked.
Was busy with different methods but this works best.
Greetings
Ronald
- 3 Replies
- 3 Participants
-
RO Ronald
- Sep 28, 2021 02:41 PM UTC
- Sep 30, 2021 04:02 AM UTC