Label + field + dropdown formatting and Field add/remove at the runtime

Hi, I checked throughout the documentation, and I cannot find info on how to:

- change formatting for both label, field, dropdown - text size, color, etc. I tried the Class "CustomTextEditor" which is supposed to work on field only, but still does not trigger

- Remove / add field on the runtime. I know that the event DataForm_AutoGeneratingDataFormItem is supposed to be used for that, using e.cancel = true, but 1) it seems this event is not triggered at all, and actually I want to remove / add field upon a change on a dropdown, so DataFormGettingStarted_PropertyChanged seems the best event to perform add/remove field.

Thanks in advance for your support

Nicolas

5 Replies

TV Thangapriya V Syncfusion Team October 10, 2017 08:37 AM UTC

Hi Nicolas, 
We have analyzed your queries. 
Regarding format labels and editors, 
You can customize the label by using GenerateViewForLabel method in DataFormLayoutManager class. 
Please refer the below UG link for this. 
You can customize the editor by using OnEditorCreated method in DataFormLayoutManager class. 
public class DataFormLayoutManagerExt : DataFormLayoutManager 
{ 
    public DataFormLayoutManagerExt(SfDataForm dataform) : base(dataform) 
    { 
    } 
    protected override void OnEditorCreated(DataFormItem dataFormItem, View editor) 
    { 
        if (dataFormItem.Name == "Name") 
        { 
            (editor as EditText).SetBackgroundColor(Color.Pink); 
        } 
        base.OnEditorCreated(dataFormItem, editor); 
    } 
} 
dataForm.LayoutManager = new DataFormLayoutManagerExt(dataForm); 
 
You can also customize the editor by using CustomEditor. 
Please refer the below UG link for this. 
Regarding remove / add field on the runtime, 
If you want to remove/add field at runtime, you need to call RefreshLayout method. It will trigger the AutoGeneratingDataFormItem event. 
Please refer the below UG link. 
Regards, 
Thangapriya 



NI Nicolas October 11, 2017 03:08 AM UTC

Hi Thangapriya,

The field and label formatting worked as a charm! As for the visible/invisible field setting, it was a bit messy as when I called the RefreshLayout in the PropertyChanged event, cause it created a loop on itself. I circumvent this by the use of  the IsVisible property as follows:

var dataFormItem1 = dataForm.ItemManager.DataFormItems["Diam"];

dataFormItem1.IsVisible = true;

Now I wonder if an event exist for commited DropDown? And I have an additional question if you allow me, how can we call a value from another, say we are in DataFormGettingStarted.cs, and we want to fetch the "Amount" variable in the RecipientInfo.cs in the runtime. Now I am using a global variable, but looking a more effective way to work this out

Thank you!

Nicolas

N.B. Found the way to get the data:

DataFormItem dfi_Diam;

dfi_Diam = dataForm.ItemManager.DataFormItems["RC_Diam"];

dia = (double)dfi_Diam.ItemManager.GetValue(dfi_Diam);






JN Jayaleshwari N Syncfusion Team October 13, 2017 11:02 AM UTC

Hi Nicolas, 
 
Please find the details about the queries. 
 
Query 
Details 
RefreshLayout in the PropertyChanged event, cause it created a loop on itself 
You can do DataFormItems manipulation like add or remove, changing visibility etc,.. based on another property in PropertyChanged event only. You can use the args.PropertyName conditional check to avoid the loop.  
 
(form.DataObject as NotificationObject).PropertyChanged += DataObject_PropertyChanged; 
 
private void DataObject_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) 
{ 
    if(e.PropertyName == "Amount")  
    { 
                                             
    } 
} 
 
Within condition you can change the Visibility of the DataFormItem. 
Now I wonder if an event exist for commited DropDown? 
Currently we don’t have an event after committing the DataFormItem values.  However you can achieve the needed operation in PropertyChanged event itself. 
 
(form.DataObject as NotificationObject).PropertyChanged += DataObject_PropertyChanged; 
 
private void DataObject_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) 
{ 
    if(e.PropertyName == "Direction") // drop down editor name. 
    { 
                                             
    } 
} 
 
 
how can we call a value from another, say we are in DataFormGettingStarted.cs, and we want to fetch the "Amount" variable in the RecipientInfo.cs in the runtime. 
You can change the value of another variable of DataFormItem from PropertyChanged event of DataObject. 
 
Please refer the below UG link. 
 
Please let us know if you have any other queries. 
 
Regards, 
 
Jayaleshwari N. 
 



NI Nicolas October 13, 2017 02:07 PM UTC

Nice!!! Work as a charm! Thank you for your support

Nicolas



JN Jayaleshwari N Syncfusion Team October 17, 2017 11:56 AM UTC

Hi Nicolas, 
  
Thanks for the update. 
Please let us know if you need further assistant on this. 
  
Regards, 

Jayaleshwari N. 


Loader.
Up arrow icon