Visibility issues with switch Editor

Hi, 

I have created a form which has a bool property which when the form first loads should be invisible until another action has been completed.

This works fine if I have a checkbox editor however when I use a switch the form item will show regardless.

Any info on how to resolve this is much appreciated.

Below is the Code I am using to set the property visibility when the form is first loaded:

private void DataForm_AutoGeneratingDataFormItem(object sender, AutoGeneratingDataFormItemEventArgs e)
  {
   if (e.DataFormItem != null)
   {
    if (e.DataFormItem.Name == "Description" || e.DataFormItem.Name == "StartDate" || e.DataFormItem.Name == "EndDate")
    {
     e.DataFormItem.LayoutOptions = LayoutType.TextInputLayout;
    }
    if (e.DataFormItem.Name == "Reminders")
    {
     e.DataFormItem.Editor = "Switch";
     e.DataFormItem.IsVisible = false;
    }
   }
  }

3 Replies

KA Karthikraja Arumugam Syncfusion Team February 14, 2020 04:49 AM UTC

Hi Gregory, 
 
Thank you contacting Syncfusion support. 
 
We have checked the mentioned issue “Switch editor visibility cannot be changed in DataForm”, since you are changing editor inside AutoGeneratingDataFormItemEvent, IsVisible property gets override after changing editor, so we suggest to use DataForm’s RegisterEdior method to set the editor as Switch. 
 
 Please refer the following code example for the same, 
  dataForm.RegisterEditor("Reminders", "Switch"); 
 
We have prepared a sample for the same, 
Sample link: DataFormSwitch 
 
You can also refer our UG documentation to know more about RegisterEditor in dataform, 
 
Regards, 
Karthik Raja A 



GR Gregory February 14, 2020 01:57 PM UTC

This worked thank you.



KA Karthikraja Arumugam Syncfusion Team February 17, 2020 05:07 AM UTC

Hi Gregory, 
 
Thank you for the update. 
 
We are glad that the given solution resolved the issue. Please get in touch with us if you need any further assistance. 
 
Regards, 
Karthik Raja 


Loader.
Up arrow icon