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

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

1 Answer 213 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Pavel
Top achievements
Rank 1
Pavel asked on 10 Nov 2016, 06:18 PM

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?

1 Answer, 1 is accepted

Sort by
0
Accepted
Dess | Tech Support Engineer, Principal
Telerik team
answered on 11 Nov 2016, 09:56 AM
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.

Regards,
Dess
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.
Tags
GridView
Asked by
Pavel
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or