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

How to bind dataformcombobox field to an enum?

4 Answers 59 Views
DataForm
This is a migrated thread and some comments may be shown as answers.
Pranav
Top achievements
Rank 1
Pranav asked on 23 Mar 2015, 11:58 AM
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?

4 Answers, 1 is accepted

Sort by
0
Accepted
Stefan
Telerik team
answered on 25 Mar 2015, 11:33 AM
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.

 
0
Eric
Top achievements
Rank 1
answered on 11 Mar 2016, 04:09 PM

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?

 

0
Stefan
Telerik team
answered on 16 Mar 2016, 09:50 AM
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.
0
Eric
Top achievements
Rank 1
answered on 18 Mar 2016, 09:02 AM

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

Tags
DataForm
Asked by
Pranav
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Eric
Top achievements
Rank 1
Share this question
or