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

IGenericListFieldInfoProvider

1 Answer 23 Views
DataForm
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Rob
Top achievements
Rank 2
Rob asked on 08 Oct 2014, 06:50 PM
Hello,

I am trying to bind a RadDataForm DataField to a property in my model. I would like to use DisplayMemberPath and SelectedValuePath in order to display a "description" to the user, but store a record id to my model
ex. Display "New York", but store "NY"

The following is not correct, throws exception "Value does not fall within the expected range."
What is correct way to implement this behavior using DisplayMemberPath and SelectedValuePath?


Model has a property defined as follows
        // State
        private string _state;
        [GenericListEditor(typeof(StateInfoProvider))]
        public string State
        {
            get { return _state; }
            set
            {
                if (_state != value)
                {
                    NotifyPropertyChanging("State");
                    _state = value;
                    NotifyPropertyChanged("State");
                }
            }
        }

IGenericListFieldInfoProvider is defined as follows:

    public class StateInfoProvider : IGenericListFieldInfoProvider
    {
        public IGenericListValueConverter ValueConverter
        {
            get { return null; }
        }
        public System.Collections.IEnumerable ItemsSource
        {
            get
            {
                List<StateInfo> states = new List<StateInfo>();
                states.Add(new StateInfo() { State = "California", StateCode = "CA" });
                states.Add(new StateInfo() { State = "New Jersey", StateCode = "NJ" });
                states.Add(new StateInfo() { State = "New York", StateCode = "NY" });
                return states;
            }
        }
    }

View is defined as follows:
            <telerikInput:RadDataForm x:Name="RadDataForm1"  ValidationMode="OnValueChanged" CommitMode="OnFieldValueChange" >
                <Grid>
                    <telerikInput:DataField TargetProperty="State" Header="State">
                        <telerikInput:DataField.CustomEditor>
                            <telerikDataForm:CustomEditor>
                                <telerikInput:RadListPicker DisplayMemberPath="State" SelectedValuePath="StateCode" />
                            </telerikDataForm:CustomEditor>
                        </telerikInput:DataField.CustomEditor>
                    </telerikInput:DataField>
                </Grid>
            </telerikInput:RadDataForm>










1 Answer, 1 is accepted

Sort by
0
Accepted
Ves
Telerik team
answered on 13 Oct 2014, 07:34 AM
Hi Rob,

In this case, you can use the default editor, created by RadDataForm -- namely the one that uses RadListPicker control, populated with the values returned by the IGenericListFieldInfoProvider. RadLIstPicker exposes the properties you need - DisplayMemberPath and SelectedValuePath. Here is an example:

<telerikInput:DataField TargetProperty="State"  x:Name="stateField">
    <telerikInput:DataField.EditorStyles>
        <Style TargetType="telerikInput:RadListPicker">
            <Setter Property="PopupHeader" Value="State"/>
            <Setter Property="DisplayMemberPath" Value="State" />
            <Setter Property="SelectedValuePath" Value="StateCode" />
        </Style>
    </telerikInput:DataField.EditorStyles>
</telerikInput:DataField>


Best regards,
Ves
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
DataForm
Asked by
Rob
Top achievements
Rank 2
Answers by
Ves
Telerik team
Share this question
or