Is there an Attribute I can use on a property to tell DataGridView how to format the column?
.net, attributes, c#, datagridview, properties
Solution
I know its not perfect but you could add another property called CurrencyBaz that would basically return a formatted Baz, then bind that to the grid instead of the real Baz.
so something like this.
private class MyClass {
[DisplayName("Foo/Bar")]
public string FooBar { get; private set; }
[Browsable(False)]
public decimal Baz { get; private set; }
[DisplayName("Baz")]
public CurrencyBaz
{
get { return string.Format(Baz, "C2"); }
}
}
Problem
Following on a bit from this question, if I have this class: ``` private class MyClass { [DisplayName("Foo/Bar")] public string FooBar { get; private set; } public decimal Baz { get; private set; } } ``` And I want to display a `List<MyClass>` in a `DataGridView` (with autogenerated columns), what's the easiest way to make the Baz column display formatted as currency? Is there an attribute I can use like I'm using `DisplayName`, or do I have to mess with the columns after they are created?