IGenericListFieldInfoProvider

2 posts, 1 answers
  1. Rob
    Rob avatar
    11 posts
    Member since:
    Jan 2013

    Posted 08 Oct 2014 Link to this post

    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>










  2. Answer
    Ves
    Admin
    Ves avatar
    2879 posts

    Posted 13 Oct 2014 Link to this post

    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.

     
  3. DevCraft banner
Back to Top