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

RadDataForm DataTemplate ComboBox

1 Answer 164 Views
DataForm
This is a migrated thread and some comments may be shown as answers.
Alex
Top achievements
Rank 1
Alex asked on 18 Aug 2011, 09:20 PM
I had an auto-generated RadDataForm but need to rearrange some of the fields and don't have access to the objects to put "Order=#"...

So I made a DataTemplate, but my combobox is not pulling in the enums that it should in the last combobox. How can I make it retrieve the enums like when it is auto-generated?

public enum CCTypes : int {
        
          VISA = 1,
        
          AmericanExpress = 2,
        
          MasterCard = 3,
        
          Discover = 4,
   }


<DataTemplate x:Key="BInfoDataFormTemplate">
        <StackPanel>
            <StackPanel Orientation="Horizontal">              
                <telerik:DataFormDataField x:Name="firstName" DataMemberBinding="{Binding FirstName, Mode=TwoWay}"
                    Label="First Name" IsRequired="True" Width="300" />
            </StackPanel>
            <StackPanel Orientation="Horizontal" Width="300">              
                <telerik:DataFormDataField x:Name="lastName" DataMemberBinding="{Binding LastName, Mode=TwoWay}"
                    Label="Last Name" IsRequired="True" Width="300" />
            </StackPanel>
            <StackPanel Orientation="Horizontal" Width="300">              
                <telerik:DataFormDataField x:Name="streetAddress" DataMemberBinding="{Binding StreetAddress, Mode=TwoWay}"
                    Label="Street Address" IsRequired="True" Width="300" />
            </StackPanel>
            <StackPanel Orientation="Horizontal" Width="300">              
                <telerik:DataFormDataField x:Name="suiteApartment" DataMemberBinding="{Binding SuiteApt, Mode=TwoWay}"
                    Label="Suite / Apt. Number" IsRequired="True" Width="300" />
            </StackPanel>
            <StackPanel Orientation="Horizontal" Width="300">              
                <telerik:DataFormDataField x:Name="city" DataMemberBinding="{Binding City, Mode=TwoWay}"
                    Label="City" IsRequired="True" Width="300" />
            </StackPanel>
            <StackPanel Orientation="Horizontal" Width="300">              
                <telerik:DataFormDataField x:Name="state" DataMemberBinding="{Binding State, Mode=TwoWay}"
                    Label="State" IsRequired="True" Width="300" />
            </StackPanel>
            <StackPanel Orientation="Horizontal" Width="300">              
                <telerik:DataFormDataField x:Name="zip" DataMemberBinding="{Binding Zip, Mode=TwoWay}"
                    Label="ZIP Code" IsRequired="True" Width="300" />
            </StackPanel>
            <StackPanel Orientation="Horizontal" Width="300">              
                <telerik:DataFormComboBoxField x:Name="cardType" DataMemberBinding="{Binding CardType, Mode=TwoWay}"
                    Label="Card Type" IsRequired="True" Width="300" />
            </StackPanel>
            <StackPanel Orientation="Horizontal" Width="300">              
                <telerik:DataFormDataField x:Name="cardNumber" DataMemberBinding="{Binding CCNumber, Mode=TwoWay}"
                    Label="Card Number" IsRequired="True" Width="300" />
            </StackPanel>
            <StackPanel Orientation="Horizontal" Width="300">              
                <telerik:DataFormDateField x:Name="cardExpDate" DataMemberBinding="{Binding CCExpirationDate, Mode=TwoWay}"
                    Label="Expiration Date" IsRequired="True" Width="300" />
            </StackPanel>
            <StackPanel Orientation="Horizontal" Width="300">              
                <telerik:DataFormDataField x:Name="cardSecNumber" DataMemberBinding="{Binding SecurityCode, Mode=TwoWay}"
                    Label="Security Code" IsRequired="True" Width="300" />
            </StackPanel>
        </StackPanel>
    </DataTemplate>

1 Answer, 1 is accepted

Sort by
0
Accepted
Maya
Telerik team
answered on 19 Aug 2011, 09:34 AM
Hello Alex,

You may utilize the Telerik EnumDataSource like follows:

//C#:
((EnumDataSource)this.LayoutRoot.Resources["MyEnumSource"]).EnumType = typeof(Position);
 
//XAML:
<telerik:EnumDataSource x:Name="MyEnumSource"  />
<telerik:DataFormComboBoxField DataMemberBinding="{Binding Position, Mode=TwoWay}"
                                                       SelectedValuePath="Value"
                                                       ItemsSource="{Binding Source={StaticResource MyEnumSource}}"
                                                       Grid.Row="3" Grid.Column="0" Label="Position" />

I am sending you a sample project illustrating the suggested approach. Let me know if you need any further assistance.
On the other hand, you may still set the order of the data fields in the AutogeneratingField event:
private void playersDataForm_AutoGeneratingField(object sender, Telerik.Windows.Controls.Data.DataForm.AutoGeneratingFieldEventArgs e)
        {
            if(e.PropertyName == "Name")
            {
                e.Order = 3;
            }
        }

Regards,
Maya
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

Tags
DataForm
Asked by
Alex
Top achievements
Rank 1
Answers by
Maya
Telerik team
Share this question
or