RadDataForm DataTemplate ComboBox

2 posts, 1 answers
  1. Alex
    Alex avatar
    10 posts
    Member since:
    Nov 2010

    Posted 18 Aug 2011 Link to this post

    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>
  2. Answer
    Maya
    Admin
    Maya avatar
    4062 posts

    Posted 19 Aug 2011 Link to this post

    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 >>

  3. DevCraft banner
Back to Top