Reputation: 2961
I'm trying to bind a list of page
classes to a 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>();
I want one row in the datagridview
to represent a row in the list
List<Tuple<DateTime, String>> Lines
With one column for the DateTime
and one for the corresponding string
.
Each row should be color
coordinated to the page
with which it belongs.
I'm trying to bind it because I want the GUI to be updated live with updates to source files.
My implementations have been going round in circles for days, any help/advice would be greatly appreciated. Thanks!
edit: some sample data:
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
Upvotes: 1
Views: 2448
Reputation: 2961
For anyone viewing this question, I fixed the problem by changing my data structure. I created a class for a single line like so:
class Line : INotifyPropertyChanged
{
public Color _c;
public DateTime _dateTime;
public String _comment;
public event PropertyChangedEventHandler PropertyChanged;
}
then implemented a BindingList
to store all the lines and followed the example Vikram linked.
BindingList<Line> all = new BindingList<Line>();
also, make sure you include this line in the form intialiser and not a method as I did!
dataGridView1.DataSource = all;
Upvotes: 2