DataFormDataField Label Bold

5 posts, 0 answers
  1. Andreas Decke
    Andreas Decke avatar
    25 posts
    Member since:
    Oct 2007

    Posted 16 Feb 2012 Link to this post

    Hello,
    in the original dataform, the label set to bold if the property is set to DataAnnatotion to [Required]. How can we do this in RadDataForm.

    greetings Andreas
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 17 Feb 2012 Link to this post

    Hello,

    Try the following code.
    C#:
    private void dataForm_AutoGeneratingField(object sender, Telerik.Windows.Controls.Data.DataForm.AutoGeneratingFieldEventArgs e)
    {
      if (e.PropertyName == "Name")
      {
          e.DataField.FontWeight = System.Windows.FontWeights.Bold;
      }
    }

    Thanks,
    Princy.
  3. DevCraft banner
  4. Andreas Decke
    Andreas Decke avatar
    25 posts
    Member since:
    Oct 2007

    Posted 17 Feb 2012 Link to this post

    Hello Princy,
    this much is clear. How do I get the information that this property is [Required]. If I do this manually, Changed the Class property to be adjusted manually in the Auto-generating field. DataForm do this automatically.

    greetings andreas
  5. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 21 Feb 2012 Link to this post

    Hello,

    Generally, you can try finding the properties that have Required attribute defined and again set FontWeight property of the corresponding data field. It could be something as follows:

    private void clubsDataForm_AutoGeneratingField(object sender, Telerik.Windows.Controls.Data.DataForm.AutoGeneratingFieldEventArgs e)
            {
                var properties = this.clubsDataForm.CurrentItem.GetType().GetProperties();
                foreach (PropertyInfo propertyInfo in properties)
                {
                    var requiredAttribute = propertyInfo.GetCustomAttributes(typeof(RequiredAttribute), true).FirstOrDefault();
                    if (requiredAttribute != null && e.PropertyName == propertyInfo.Name)
                    {
                        e.DataField.FontWeight = System.Windows.FontWeights.Bold;
                    }
                }
            }

    I am attaching a sample project illustrating the suggested approach. 
      Regards,
    Maya
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  6. Andreas Decke
    Andreas Decke avatar
    25 posts
    Member since:
    Oct 2007

    Posted 22 Feb 2012 Link to this post

    Hello,
    wonderful, it works fine ..
    thanks
Back to Top
DevCraft banner