How to set TextBox backgrounds when autogenerating fields

2 posts, 0 answers
  1. Peter
    Peter avatar
    37 posts
    Member since:
    Dec 2011

    Posted 23 Feb 2014 Link to this post

    I'm autogenerating the fields of my RadDataForm. 

    Now I want to set different background colors for the TextBoxes being generated. For example Textbox of property 'Name' should have a green background and Textbox for property 'Age' should have a blue background.

    In RadGridViews the autogenerator can set very comfortably GridViewAutoGeneratingColumnEventArgs.Column.CellStyle, but how do I do this in a DataForm?
  2. Yoan
    Yoan avatar
    1128 posts

    Posted 24 Feb 2014 Link to this post

    Hi Peter,

    You can try the following approach:
    private void RadDataForm_AutoGeneratingField(object sender, Telerik.Windows.Controls.Data.DataForm.AutoGeneratingFieldEventArgs e)
             if (e.PropertyName=="Name")
                 e.DataField.Loaded += new RoutedEventHandler(DataField_Loaded);           
         void DataField_Loaded(object sender, RoutedEventArgs e)
             if ((sender as DataFormDataField).Content is TextBox)
                 ((sender as DataFormDataField).Content as TextBox).Background = new SolidColorBrush(Colors.Green);

    I hope it helps.

Back to Top