Set Values For TKDataFormSegmented Editor

4 posts, 1 answers
  1. Nicholas
    Nicholas avatar
    2 posts
    Member since:
    Apr 2016

    Posted 26 May Link to this post

    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

  2. Answer
    Adrian
    Admin
    Adrian avatar
    167 posts

    Posted 31 May Link to this post

    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
  3. DevCraft banner
  4. Nicholas
    Nicholas avatar
    2 posts
    Member since:
    Apr 2016

    Posted 31 May in reply to Adrian Link to this post

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

    Nick

  5. Adrian
    Admin
    Adrian avatar
    167 posts

    Posted 02 Jun Link to this post

    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
Back to Top
DevCraft banner