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?
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"); }
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With