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

Set Values For TKDataFormSegmented Editor

3 Answers 107 Views
DataForm - Xamarin.iOS
This is a migrated thread and some comments may be shown as answers.
Nicholas
Top achievements
Rank 1
Nicholas asked on 26 May 2016, 05:02 PM

Hi, I was wondering if there was a way to specify the values that come back from a Data Form Segmented Editor. If I supply an array with four values to the ValuesProvider for the editor, instead of the default 0-3 values that would come back depending on what was selected, can we supply it with values for each option so that it comes back as 1-4 instead of 0-3. I was going to try and create a TKDataSource with an object that had a name and value, but it doesn't look like you can attach a TKDataSource to a segmented editor. Am I stuck with the default values in this case?

Thanks,

Nick

3 Answers, 1 is accepted

Sort by
0
Accepted
Adrian
Telerik team
answered on 31 May 2016, 03:10 PM
Hi, Nicholas,

Thank you for contacting us.
TKDataFormSegmented editor can return either the index value of the selected segment or the actual value that the segment displays out of the box. This can be done by using the PickersUseIndexValue property of TKEntityProperty. If you still need to return other values that are not the segment's indexes or the displayed value you should adopt TKDataFormDelegate protocol and implement its SetupEditor method and edit the titles of the segmented control like shown below:
public override void SetupEditor (TKDataForm dataForm, TKDataFormEditor editor, TKEntityProperty property)
{
    if (editor.IsKindOfClass(new ObjCRuntime.Class("TKDataFormSegmentedEditor"))) {
        UISegmentedControl segmentedControl = (editor as TKDataFormSegmentedEditor).SegmentedControl;
        segmentedControl.SetTitle ("Title 1", 0);
        segmentedControl.SetTitle ("Title 2", 1);
        segmentedControl.SetTitle ("Title 3", 2);
    }
}

This would be the values that the user will see. You should then use the ValuesProvider of TKEntityProperty to set the values that you need to be returned by the editor and set PickersUseIndexValue to false:
NSNumber[] values = new NSNumber[] { 1, 2, 3 };
this.dataSource ["InfoProtocol"].ValuesProvider = NSArray.FromObjects(values);
this.dataSource ["InfoProtocol"].PickersUseIndexValue = false;

This way the returned values by the editor would be 1, 2 or 3 for the corresponding segments.
I hope this helps. If you have further questions, do not hesitate to contact us.

Regards,
Adrian
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
Nicholas
Top achievements
Rank 1
answered on 31 May 2016, 04:50 PM

Thank you, that is exactly what I was looking for.

Nick

0
Adrian
Telerik team
answered on 02 Jun 2016, 08:29 AM
Hi, Nicholas,

I am glad that the issue is solved.

Regards,
Adrian
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
Tags
DataForm - Xamarin.iOS
Asked by
Nicholas
Top achievements
Rank 1
Answers by
Adrian
Telerik team
Nicholas
Top achievements
Rank 1
Share this question
or