This is a migrated thread and some comments may be shown as answers.

DataForm PickerEditor

7 Answers 110 Views
DataForm
This is a migrated thread and some comments may be shown as answers.
Yakup
Top achievements
Rank 1
Yakup asked on 31 Dec 2019, 02:35 PM

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?

 

7 Answers, 1 is accepted

Sort by
0
Lance | Manager Technical Support
Telerik team
answered on 31 Dec 2019, 03:58 PM

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
0
Yakup
Top achievements
Rank 1
answered on 31 Dec 2019, 06:09 PM
Thank you so much
0
Brad
Top achievements
Rank 1
answered on 28 May 2020, 03:55 PM

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.

0
Brad
Top achievements
Rank 1
answered on 29 May 2020, 02:20 PM

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

 

0
Lance | Manager Technical Support
Telerik team
answered on 29 May 2020, 02:54 PM

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.
0
Phil
Top achievements
Rank 1
Veteran
Iron
answered on 09 Feb 2021, 11:14 AM

I was looking into how to do this and the article was great.

I am able to now create the convertors for the different platforms.

Is there a way to tell the item which one is selected?

Currently it chooses the first one in the list.

If I have a dropdown with:
"Cat"
"Dog"
"Goat"

The user already has "Goat" as an option. Is it possible to get it to highlight that option using the datasource in some way?

Thanks

0
Yana
Telerik team
answered on 12 Feb 2021, 10:38 AM

Hello Phil,

You can set a default value inside the Source Item definition: 

[DisplayOptions(Header = "City")]
 public City City { get; set; } = new City("London");

or when setting the Source of the DataForm:

 this.dataForm.Source = new SourceItem() { City = new City("London") };

I hope I was of help.

Regards,
Yana
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
DataForm
Asked by
Yakup
Top achievements
Rank 1
Answers by
Lance | Manager Technical Support
Telerik team
Yakup
Top achievements
Rank 1
Brad
Top achievements
Rank 1
Phil
Top achievements
Rank 1
Veteran
Iron
Yana
Telerik team
Share this question
or