DataForm PickerEditor

6 posts, 0 answers
  1. Yakup
    Yakup avatar
    7 posts
    Member since:
    Dec 2019

    Posted 31 Dec 2019 Link to this post

    Hi, I have a problem,

    public class FruitModel
        {
            public int fruit{ get; set; }
            public string fruitName{ get; set; }
        }

    ObservableCollection<FruitModel> FruitData = newObservableCollection<FruitModel>();
     FruitData.Add(new FruitModel {fruidID = 1, fruidName ="Banana" }); .........................................

    How can i show fruit in the DataForm PickerEditor?

     

  2. Lance | Manager Technical Support
    Admin
    Lance | Manager Technical Support avatar
    1158 posts

    Posted 31 Dec 2019 Link to this post

    Hello Yakup,

    Before going any further, please take 5 minutes to follow the tutorial in the DataForm DataSourceKey Attribute documentation. You can also visit the SDKBrowser DataForm Editors demo source code (it uses a PickerEditor for the Genre property, see the UserDataSourceProvider class).

    This is a critical piece of information to understand how items are set to editors that show a list of items.

    Passing Fruits Collection

    To directly answer your question, this isn't something you can directly bind to by itself. You need to use the provider as seen in the documentation I linked to.

    That being said, you can design the provider class to accept a collection of items that you pass to it. For example, using the Locations demo from the tutorial:

    public class FruitsProvider : PropertyDataSourceProvider
    {
        private IEnumerable<FruitModel> fruits;
    
        public FruitsProvider(IEnumerable<FruitModel> sourceFruits)
        {
            this.fruits = sourceFruits;
        }
    
        public override IList GetSourceForKey(object key)
        {
            if (key.ToString() == "FruitsSource")
            {
                return this.fruits;
            }
    
            return null;
        }
    }

     

    Now, you can instantiate the provider with your FruitData

    dataForm.PropertyDataSourceProvider = new FruitsProvider(this.FruitData);
    dataForm.RegisterEditor("Fruits", EditorType.PickerEditor);

    I hope this helps answer your question.

    Regards,
    Lance | Team Lead - US DevTools Support
    Progress Telerik

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. Yakup
    Yakup avatar
    7 posts
    Member since:
    Dec 2019

    Posted 31 Dec 2019 in reply to Lance | Manager Technical Support Link to this post

    Thank you so much
  4. Brad
    Brad avatar
    2 posts
    Member since:
    May 2020

    Posted 28 May in reply to Lance | Manager Technical Support Link to this post

    Hello Lance, can the provider only support simple types such as strings? Is it possible to have a key value pair such as Id=0 and Name = "Apple" and bind this key value pair to the data source so on Edit Value Changed, I can lookup the key value pair by Id. 

    Also, how do you set an existing value? see attached files for my example.

  5. Brad
    Brad avatar
    2 posts
    Member since:
    May 2020

    Posted 29 May in reply to Brad Link to this post

    In general, RadDataForm works with simple property types (string, int, long) and when you are using a custom type - the native Data Form is not sure what native type corresponds to the one you are using so it disregards the property. 

    https://docs.telerik.com/devtools/xamarin/knowledge-base/dataform-complextype-in-editors

     

  6. Lance | Manager Technical Support
    Admin
    Lance | Manager Technical Support avatar
    1158 posts

    Posted 29 May Link to this post

    Hello Brad,

    Thank you for sharing the KB article in this forum thread. It helps explain how the DataForm is an abstraction around the native platform's controls.

    Regards,
    Lance | Team Lead - US DevTools Support
    Progress Telerik

    Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
    Our thoughts here at Progress are with those affected by the outbreak.
Back to Top