2012-10-04 23 views
1

我試圖將page類的列表綁定到datagridviewDataBinding DataGridView列表列表c#複雜集合

class Page : INotifyPropertyChanged 
{ 
    public List<Tuple<DateTime, String>> Lines { get; set; } 
    public Color c { get; set; } 
    public String filePath { get; set; } 

//rest of class code... 
} 
//on the 'Form1' class 
BindingList<Page> pages = new BindingList<Page>(); 

我想在datagridview一行表示列表

List<Tuple<DateTime, String>> Lines 

一排爲DateTime,一個用於相應的string一列。

每行應該是color協調到它所屬的page

我在試圖綁定它,因爲我想讓GUI更新到源文件的更新。

我的實現已經圍繞幾天進行了循環,任何幫助/建議將不勝感激。謝謝!

編輯:一些示例數據:

20-Apr-11 08:36:44.312 Start  I *** C:\Cromos 3.0\toolset\Ntbin\Release\crm_gui_gtm.exe on BENJAMIN-PC - release - cromos: build 2780, Gui version: 400, File version: 80 *** 
20-Apr-11 08:36:44.312 symbol element total: 9 
+0

所以......如果你有3個'頁面',其中每個都有2個'Lines' - 那總共是6行? –

+0

準確地說,一些示例數據:20-Apr-11 08:36:44.312開始,11年4月20日08:36:44.312符號元素總數:9 – Jimmy

+0

好吧,將其平鋪到單個列表中很容易,但是:在保留更改通知(列表和項目)的同時做到這一點非常困難。我會建議:保持簡單。 –

回答

2

對於任何人觀看了這個問題,我改變我的數據結構解決了這一問題。我創建了一個類一行像這樣:

class Line : INotifyPropertyChanged 
{ 
    public Color _c; 
    public DateTime _dateTime; 
    public String _comment; 
    public event PropertyChangedEventHandler PropertyChanged; 
} 

然後實施了BindingList來存儲所有的行和隨後維克拉姆鏈接的例子。

 BindingList<Line> all = new BindingList<Line>(); 

此外,請確保您在形式intialiser中包含此行,而不是像我一樣的方法!

  dataGridView1.DataSource = all;