GetSource override to generate picker lists in sfDataForm not being called in iOS. Working in Droid

Hi, 

I have followed the example in the article here: https://help.syncfusion.com/xamarin/sfdataform/editors to generate a list of items for 2 fields requiring a list to choose from within an sfDataForm control. 

These fields appear as picker controls and are populated correctly when running my project in Android. 

However when I'm running the project under iOS these same fields appear as plain text fields. 

When debugging I noticed that the GetSource override is not being called when running under iOS (and is called in Android); 

Do you have any ideas as to why this might be the case? 

Thanks,
John


5 Replies

VR Vigneshkumar Ramasamy Syncfusion Team July 24, 2018 12:58 PM UTC

Hi John,  
   
We have analyzed your query with custom picker editor in SfDataForm.  
   
By default, the ItemsSource for picker is auto-generated for enum types and in order to display the picker other than enum data type, you need to set the ItemSource of property type in SourceProvider of SfDataForm which is used to add custom ItemsSource of DataFormPickerItem.  
   
Regarding query with when I'm running the project under iOS these same fields appear as plain text fields.   
   
Based on the provided information, we suspect that you have registered the data form editor as DropDown for list and it will not be supported in Xamarin.iOS platform.  
   
Please refer the below user guide notes details.  
   
Further, you can register the supported editor which is Picker in Xamarin.iOS platform for picker data type in SfDataform.  
   
Please refer the below link for more details.   
   
We have prepared a sample by registering picker and dropdown editor in the data form. Please find the sample from the below link,  
   
Sample:  FormsSampleApp
  
  
Code snippet:  
  
  
            dataForm.DataObject = new Company();  
            dataForm.SourceProvider = new SourceProviderExt();  
            if (Device.RuntimePlatform == Device.iOS || Device.RuntimePlatform == Device.Android)  
            {  
                dataForm.RegisterEditor("ItemName""Picker");  
            }  
            else if (Device.RuntimePlatform == Device.UWP)  
                dataForm.RegisterEditor("ItemName""DropDown");  
  
    public class SourceProviderExt : SourceProvider  
    {  
        public override IList GetSource(string sourceName)  
        {  
            var list = new List<string>();  
            if (sourceName == "ItemName")  
            {  
                list.Add("Item1");  
                list.Add("Item2");  
                list.Add("Item3");  
            }  
            return list;  
        }  
    }  
  
public class Company  
    {  
        public Company()  
        {  
        }  
  
        private string _ItemName;  
        public string ItemName  
        {  
            get  
            {  
                return _ItemName;  
            }  
            set  
            {  
                _ItemName = value;  
            }  
        }  
  
    }  
  
  
  
If the shared information does not meet your scenario, could you please revert us back with more details related about your query, which will be helpful for us to analyze further and provide you a possible solution.  
 
Regards 
Vigneshkumar R 



JD John Diamond July 25, 2018 11:36 PM UTC

Thanks for your help. 

Changing to a "Picker" type control has resolved the problem in iOS. 


VR Vigneshkumar Ramasamy Syncfusion Team July 26, 2018 04:31 AM UTC

Hi John, 
 
We are glad to know that your requirement has been achieved. Please get in touch if need further assistance on this.  
 
Regards 
Vigneshkumar R 



JD John Diamond July 26, 2018 05:02 AM UTC

Hi, 

I'm not sure if I should create a new thread for this question or not but it relates to the previous information I've provided. 

I'm currently trying to get the text color of the controls to change depending upon whether the dataForm state is 'Enabled'. 

When it's not Enabled I'd like the text color of all entry controls to be in Gray otherwise Black when editable (Enabled). 

I have been able to set this for the other text controls by using CustomTextEditor, OnInitializeView and RefreshLayout. 

However for the Picker controls I've not yet found a way that I can do this. 

Do you have a recommendation?

Thanks,
John


VR Vigneshkumar Ramasamy Syncfusion Team July 28, 2018 04:55 AM UTC

Hi John,  
  
Based on the provided information we have checked your query with changing the text color of picker selected item in Picker editor field.  
  
  
Your requirement for setting Text color for Picker text items can be achieved using custom editor, where CustomPickerEditor is inherited either through DataFormPickerEditor or create the custom editor by overriding the DataFormEditor   class. Currently there is an issue in SfDataForm when TextColor for Picker items is set through DataFormPickerEditor. We have logged issue report for the same. We will fix this issue and include this fix in our upcoming Volume 2 SP2 release.  
   
We have prepared a sample for changing the text color of Picker editor selected item in SfDataForm using custom picker editor. Kindly find the sample below.  
   
  
Sample: CustomPickerSample
  
  
Code snippet :  
  
public enum Items
        {
            Item1,
            Item2,
            Item3
        }    
   
 public Items ItemName { getset; }  
   
 dataForm.RegisterEditor("Picker"new CustomPickerEditor(dataForm));
            dataForm.RegisterEditor("ItemName""Picker");
   
public class CustomPickerEditor : DataFormEditor<Picker>
    {
        public CustomPickerEditor(SfDataForm dataForm) : base(dataForm)
        {

        }
        protected override Picker OnCreateEditorView()
        {
            return new Picker();
        }
        protected override void OnInitializeView(DataFormItem dataFormItem, Picker view)
        {
            view.TextColor = Color.Green;  
             view.Items.Add("Home");  
             view.Items.Add("Utilities");  
             view.Items.Add("Products");
        }
    }  
  
  
  
You can refer our user guide documentation for creating new custom editor.  
  
  
If the provided solution doesn’t meet your requirement, could you please revert us back with modifying the provided sample with more information? It will be helpful for us to analyze on it and provide you better solution.  
 
Vigneshkumar R 


Loader.
Up arrow icon