I have a class like this:
private class MyClass {
[DisplayName("Foo/Bar")]
public string FooBar { get; private set; }
public string Baz { get; private set; }
public bool Enabled;
}
When I create a List<MyClass>
and assign it to the DataSource
of a DataGridView
, the grid shows me two columns, "Foo/Bar" and "Baz". This is what I want to happen.
It currently works because Enabled is a field, not a property - DataGridView will only pick up properties. However, this is a dirty hack.
I would like to make Enabled a property too, but still hide it on the DataGridView.
I know I can manually delete the column after binding.. but that's not ideal.
Is there an attribute similar to DisplayName, that I can tag a property with? Something like [Visible(false)]
?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…