2009-03-03 20 views
2

我有一個DataGridView,其DataSource我設置爲List<T>。在這種情況下,T是一個屬性,名爲Foo,其標題我想顯示爲Foo bar什麼是最簡單的方法來重命名DataGridView的列顯示列表<T>?

如果它是一個DataTable,我可以更改查詢:

select Foo as [Foo bar] from Baz 

但是像這樣的東西,在這裏我設置在DataGridView的DataSource爲List<Baz>

public class Baz { 
    public string Foo { get; set; } 
} 

我不能將「Foo」重命名爲「Foo bar」,因爲它包含空格。我必須手動重命名DataGridViewColumn嗎?

最真棒的事情是,如果我可以使用類的裝飾,這樣的事情:

public class Baz { 
    [DataGridViewColumnTitle("Foo bar")] 
    public string Foo { get; set; } 
} 

但我就我所看到的,沒有像在標準庫中存在。

我最好的選擇是什麼?

回答

4
[DisplayName("Foo bar")] 

(位於System.ComponentModel命名空間; MSDN

+0

美麗!我知道它必須存在:) – Blorgbeard 2009-03-03 02:09:46

相關問題