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

How to set TextBox backgrounds when autogenerating fields

1 Answer 192 Views
DataForm
This is a migrated thread and some comments may be shown as answers.
Peter
Top achievements
Rank 1
Peter asked on 23 Feb 2014, 07:13 PM
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?

1 Answer, 1 is accepted

Sort by
0
Yoan
Telerik team
answered on 24 Feb 2014, 10:21 AM
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.

Regards,
Yoan
Telerik
Tags
DataForm
Asked by
Peter
Top achievements
Rank 1
Answers by
Yoan
Telerik team
Share this question
or