Nikita
Nikita

Reputation: 173

Bind object to winForms control element

I have a class named OrganizerNote with fields: public long id; public DateTime CreationDate; public string Title; public string Note;

Also I have a class public class XMLOrganizer that has 1 field:
public List<OrganizerNote> Notes=new List<OrganizerNote>();

For example, I have several objects:

OrganizerNote n1 = new OrganizerNote();
OrganizerNote n2 = new OrganizerNote();

with some data in fields. Then I create 1 object

XMLOrganizer xmlOrg = new XMLOrganizer();
xmlOrg.Notes.Add(n1);
xmlOrg.Notes.Add(n2);

So I need to bind each xmlOrg.Notes[0] ... xmlOrg.Notes[i] to Row[i] in datagridView control. And fields values would be in columns.

How could I do so?

Upvotes: 0

Views: 391

Answers (1)

ssmithstone
ssmithstone

Reputation: 1209

make

List<OrganizerNote> Notes=new List<OrganizerNote>();

into

BindingList<OrganizerNote> Notes=new BindingList<OrganizerNote>();

and then create a binding source on the form bind that to the database and then set the binding datasource to the Notes field on the XMLOranizer

Upvotes: 1

Related Questions