dataform drop down field bound to collection of entities

I have an entity (just a POCO) called LookupValue. This class has two fields a Title and a Value. I use this entity for all types of drop down values (i.e. list of 50 U.S. states). I have a web service that returns a whole bunch of look up values that can be configured from a database. I'd like my Xamarin.Forms app to be able to consume these values by using a drop down field in the Data Form control to select one of them. However, I seem to be having trouble following the SourceProvider documentation found here: https://help.syncfusion.com/xamarin-android/sfdataform/editors

I've set my source provider and I've set the editor type manually but a drop down field still does not appear in the form.

Here's where I set the dataForm up in the view:


        public PersonPrimaryResidenceEditorView ()
{
InitializeComponent ();

            this.BindingContext = viewModel = new PersonPrimaryResidenceEditorViewModel();

            dataForm.SourceProvider = new SourceProviderExt();
            dataForm.RegisterEditor(typeof(LookupValue), "DropDown");
        }

Here is my source provider implementation:


    public class SourceProviderExt : SourceProvider
    {
        public override IList GetSource(string sourceName)
        {
            var list = new List<LookupValue>();
            if (sourceName == "Province")
            {
                list.Add(new LookupValue("Ohio", "OH"));
                list.Add(new LookupValue("California", "CA"));
            }
            return list;
        }
    }

Here is the property on the form:

        private LookupValue province;
        [Display(ShortName = "State")]
        [Required(AllowEmptyStrings = false, ErrorMessage = "Please enter your state.")]
        public LookupValue Province
        {
            get { return this.province; }
            set
            {
                if (value != Province)
                {
                    this.province = value;
                    this.RaisePropertyChanged("Province");
                    this.RaiseErrorChanged("Province");
                }
            }
        }


I am starting to think that only Enums or List<string> is supported which would be very disappointing.

10 Replies

JN Jayaleshwari N Syncfusion Team October 18, 2018 09:21 AM UTC

Hi Mark, 
 
Thanks for Contacting Syncfusion Support. 
 
We have checked the reported query “Drop down field only support Enum or List<string>” from our side. Currently we does not have support to list the entity values for DropDown control.  
However, As of now you can use our Picker editor for your requirement. But based on the implementation of 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.   
  
To display complex type properties (other than enum data type) it can be done only as mentioned in the below user guide documentation and complex class cannot be directly set as data type for picker editor in this scenario.   
  
 
We have prepared the sample based on picker and attached the same for your reference. You can download from the following location. 
 
 
We have already logged the feature report to support DisplayMemberPath and ValueMemberPath for DataFormDropDownItem as like we provide support for Picker. The feature will be included in our upcoming Volume 3 SP1 release which is scheduled to be rolled out by the end of October, 2018.  
 
 
Please let us know if you need further assistance.   
 
Regards, 
Jayaleshwari N. 



MA Mark October 20, 2018 03:36 PM UTC

Thanks for the tip. It is exactly what I needed. I'm using a Picker 

dataForm.RegisterEditor("City", "Picker");

and I'm binding to complex types now too!

                if (e.DataFormItem.Name.Equals("SelectedValue"))
                {
                    if (Device.RuntimePlatform != Device.UWP)
                    {
                        (e.DataFormItem as DataFormPickerItem).DisplayMemberPath = "Title";
                        (e.DataFormItem as DataFormPickerItem).ValueMemberPath = "Code";
                    }
                }

my source provider also returns my complex type:

        public override IList GetSource(string sourceName)
        {
            var list = new List<LookupValue>();
            if (key == "SEX")
            {
                list.Add(new LookupValue("MALE", "1"));
                list.Add(new LookupValue("FEMALE", "2"));
            }

much appreciated!


MA Mark replied to Jayaleshwari N October 21, 2018 06:42 PM UTC

Hi Mark, 
 
Thanks for Contacting Syncfusion Support. 
 
We have checked the reported query “Drop down field only support Enum or List<string>” from our side. Currently we does not have support to list the entity values for DropDown control.  
However, As of now you can use our Picker editor for your requirement. But based on the implementation of 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.   
  
To display complex type properties (other than enum data type) it can be done only as mentioned in the below user guide documentation and complex class cannot be directly set as data type for picker editor in this scenario.   
  
 
We have prepared the sample based on picker and attached the same for your reference. You can download from the following location. 
 
 
We have already logged the feature report to support DisplayMemberPath and ValueMemberPath for DataFormDropDownItem as like we provide support for Picker. The feature will be included in our upcoming Volume 3 SP1 release which is scheduled to be rolled out by the end of October, 2018.  
 
 
Please let us know if you need further assistance.   
 
Regards, 
Jayaleshwari N. 


Upon further inspection, while I am able to get the form to LOAD correctly with this approach. When I try to save the data on the form using this approach I run into problems. It turns out the setter on the "Province" property will only be set to a String which is the ToString() of the class. this means that if you do not implement the ToString method in your class you will run into a problem where the value will always be "sfDataFormSample.LookupValue" or whatever you class name is. Why doesn't the Picker use the ValueMember and reflection to obtain the actual value to put on the setter rather than relying on the object.ToString()? This would be a much cleaner implementation.

Attachment: syncfusion_problem_6e058e34.zip


JN Jayaleshwari N Syncfusion Team October 24, 2018 12:33 PM UTC

Hi Mark,  
  
We have analyzed with your query related to using complex property in picker (Using ValueMemberPath and DisplayMemberPath) while saving the data in SfDataForm in Xamarin Forms.As you have mentioned in earlier update, initially while loading the complex picker data item no issue occurs. Could you please revert us back with exact replication procedure like how the data is saved in your sample application? Or kindly explain the exact requirement in simple steps along with sample code if possible along with the Xamarin platform used and SfDataForm version used. Such that it will be helpful for us to analyze and provide you possible solution.  
 
Regards, 
Jayaleshwari N 



JN Jayaleshwari N Syncfusion Team December 11, 2018 09:18 AM UTC

Hi Mark,   
   
We are glad to announce that our Essential Studio 2018 Volume 4 beta Release v16.4.0.40 is rolled out and is available for download under the following link.    
    
     
Support for DisplayMemberPath and ValueMemberPath in DataFormDropDownItem and “Display the complex property type using DisplayMemberPath and ValueMemberPath” has been provided and included in this release .We thank you for your support and appreciate your patience in waiting for this release. Please get in touch with us if you would require any further assistance.    
    
Regards,    
Jayaleshwari N. 



SG Swathi Gopal Syncfusion Team December 18, 2018 10:37 AM UTC

Hi Mark, 
 
We are glad to announce that our Essential Studio 2018 Volume 4 Release v16.4.0.42 is rolled out and is available for download under the following link. 
  
  
Support for DisplayMemberPath and ValueMemberPath in DataFormDropDownItem and display the complex property type using DisplayMemberPath and ValueMemberPath has been provided in SfDataForm and included in this release. Kindly find the simple sample for the provided support below, 
 
 
We thank you for your support and appreciate your patience in waiting for this release. Please get in touch with us if you would require any further assistance. 
  
Regards, 
Swathi G 



MI Michael October 17, 2020 05:34 PM UTC

Have there been changes to this implementation? 

When I try this approach with a dataobject of an own type then these Attributes will be added as TextItems with the 
Country.Name, 
Country.Continent and so on. 
And I'm not able to change any assignments.


SS SaiGanesh Sakthivel Syncfusion Team October 19, 2020 12:10 PM UTC

Hi Micheal, 
 
Thank you for the contacting syncfusion support. 
 
#Regarding Display the complex property type using DisplayMemberPath and ValueMemberPath 
We would like to inform you that we have prepared the sample as per the given information. Please refer to the following demo sample link for your reference. 
 
 
Please check our sample and let us know if you still facing the same issue? If not, please modify our sample based on your scenario and revert us back with the following details,  
 
·       Syncfusion and Xamarin.Forms update version. 

It will be helpful for us to check on it and provide you the solution at the earliest. 

Regards,
SaiGanesh Sakthivel 
 



MI Michael October 19, 2020 02:21 PM UTC

Thanks for the reply, but the scenario is a bit different, as I have already an Object instead of the string City

CityModel City

 public class CityModel
    {
        public string Name { get; set; }
        public string AreaCode { get; set; }
        public string County { get; set; }
    }

how would that work then? 



SS SaiGanesh Sakthivel Syncfusion Team October 20, 2020 11:44 AM UTC

Hi Michael, 
 
Thank you for the update. 
 
We would like to inform you that display the complex property type using DisplayMemberPath and ValueMemberPath should contain string type of property. As we are mentioned in UG documentation, Class cannot be directly set as data type for drop down editor in this complex type scenario. Please refer to the UG documentation in the following link. 
 
 
Please let us know if you have any concern. 
 
Regards, 
SaiGanesh Sakthivel 


Loader.
Up arrow icon