数据绑定DataGridView列表c#复杂集合
我正在尝试将数据绑定DataGridView列表c#复杂集合,c#,list,data-binding,collections,datagridview,C#,List,Data Binding,Collections,Datagridview,我正在尝试将page类的列表绑定到datagridview 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
page
类的列表绑定到datagridview
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>();
一列用于日期时间
,另一列用于相应的字符串
每行的颜色应与所属的页面协调
我正在尝试绑定它,因为我希望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
对于任何查看此问题的人,我通过更改数据结构修复了此问题。我为一行创建了一个类,如下所示:
class Line : INotifyPropertyChanged
{
public Color _c;
public DateTime _dateTime;
public String _comment;
public event PropertyChangedEventHandler PropertyChanged;
}
然后实现了一个BindingList
来存储所有行,并遵循Vikram链接的示例
BindingList<Line> all = new BindingList<Line>();
所以如果你有3个
页面
s,每个页面都有2行——总共是6行?确切地说,一些示例数据:20-Apr-11 08:36:44.312 Start,20-Apr-11 08:36:44.312 symbol element total:9好吧,将其扁平化为一个列表很容易,但是:在保留更改通知的同时这样做(在列表和项目上)坦白地说太难了。我建议:保持简单。我已经使用filesystemwatcher获得了功能并输出到listview。但是datagridview提供了内置排序,这将使实现更简单、更快速…如果我能弄明白的话!
BindingList<Line> all = new BindingList<Line>();
dataGridView1.DataSource = all;