How to bind dataformcombobox field to an enum?

5 posts, 1 answers
  1. Pranav
    Pranav avatar
    3 posts
    Member since:
    Mar 2015

    Posted 23 Mar 2015 Link to this post

    I have a datadormcombobox field in raddataform i have tried to set Items source property binding to Enum ""but it wont load contents from enum.Also if I set autogenerate fields property to true then it  loads enum in combobox.so whats wrong with manual setting?
  2. Answer
    Stefan X1
    Admin
    Stefan X1 avatar
    514 posts

    Posted 25 Mar 2015 Link to this post

    Hi Pranav,

    A way of achieving this is to use EnumDataSource class in your Business Object, as suggested below:
    public EnumDataSource PositionEnum
    {
        get
        {
            return new EnumDataSource { EnumType = typeof(Position) };
        }
    }

    Then you should be able to set the enum values as an ItemsSource of DataFormComboBoxFiled:
    <telerik:DataFormComboBoxField
                  ItemsSource="{Binding CurrentItem.PositionEnum,
        RelativeSource={RelativeSource AncestorType=telerik:RadDataForm},
        Mode=OneWay}">
    </telerik:DataFormComboBoxField>


    You can also check the Binding Enum to DataFormComboBoxField forum thread for further reference.

    I hope that this helps.

    Best Regards,
    Stefan
    Telerik
     

    See What's Next in App Development. Register for TelerikNEXT.

     
  3. UI for WPF is Visual Studio 2017 Ready
  4. Eric
    Eric avatar
    4 posts
    Member since:
    Aug 2010

    Posted 11 Mar in reply to Stefan X1 Link to this post

    Hi Stefan,

    I'm trying to achieve the same here; binding a enum value to a DataFormComboBoxField of a DataForm in WPF.

    Your ItemSource doesn't seems te work. It's not populating the ComboBox and it's not showing the current value.

    What is the correct definition for binding an enum?

     

  5. Stefan X1
    Admin
    Stefan X1 avatar
    514 posts

    Posted 16 Mar Link to this post

    Hello Eric,

    From the provided information, I guess that you have binding errors. Can you please check this out? They can be observed in the output window in Visual Studio when debugging the application.

    I have also prepared a sample application, demonstrating how the EnumDataSource can be used to populate DataFormComboBoxField.

    Hope this helps.


    Best Regards,
    Stefan X1
    Telerik
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
  6. Eric
    Eric avatar
    4 posts
    Member since:
    Aug 2010

    Posted 18 Mar in reply to Stefan X1 Link to this post

    Hi,

    Thank you for your reply.

    I've fixed the issue with the following;

    <telerik:DataFormComboBoxField 
        Label="Gender"
        DisplayMemberPath="DisplayName"                                                    
        SelectedValuePath="Value"                                                    
        ItemsSource="{Binding DataContext.GenderEnum, ElementName=Main, Mode=OneWay}"
        DataMemberBinding="{Binding Gender, Mode=TwoWay}" />

    GenderEnum is of type EnumDataSource

Back to Top
UI for WPF is Visual Studio 2017 Ready