RadGridView AutogenerateColumns. How much can I do with attributes alone?

2 posts, 1 answers
  1. Pavel
    Pavel avatar
    32 posts
    Member since:
    Sep 2016

    Posted 10 Nov 2016 Link to this post

    I would love to avoid having to create columns by hand, and just rely on auto generation. I know I can set a title of the column by adding a DisplayName attribute. However, when I try to set a date format, it's breaking.

    Here's what I am trying to do

    [DisplayName("Invoice Date")]
    [DisplayFormat(DataFormatString = "{0:MM/dd/yyyy}")]
    public DateTime? InvoiceDate { get; set; }

    However, the date still displays with the time.

    Also, is there a way to get a column to be hidden through attributes alone?

  2. Answer
    Dess | Tech Support Engineer, Sr.
    Dess | Tech Support Engineer, Sr.  avatar
    4086 posts

    Posted 11 Nov 2016 Link to this post

    Hello Pavel,

    Thank you for writing.  

    Currently, RadGridView doesn't consider the DisplayFormatAttribute when automatically generates the column. However, it seems to be a reasonable request. I have logged it in our feedback portal and I have added a vote for it on your behalf. You can track its progress, subscribe for status changes and add your comments on the following link - feedback item.

    I have also updated your Telerik points.

    Currently, the possible solution that I can suggest is to GridViewDateTimeColumn.FormatString property of the column after binding the grid.

    As to the question about controlling the visibility of the column, you can use the BrowsableAttribute.

    I hope this information helps. Should you have further questions I would be glad to help.

    Telerik by Progress
    Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms.For more information check out this blog post and share your thoughts.
Back to Top