c# - How to display the contents of a list into a DataGridView in winforms -
my problem simple. making calendar school project. need add properties list of objects in order save event calendar. have managed add things list, have not found way display events of list in winforms. professor suggested use datagridview display contents of list. can show me how can bind objects in list datagridview, , whenever add list adds grid? appreciated.
here have far:
public static list<event> events = new list<event>(); [stathread] static void main() { application.enablevisualstyles(); application.setcompatibletextrenderingdefault(false); application.run(new form1()); } public static void addevent(string eventdate, string eventtitle, string eventinfo) { event event = new event(); event.eventdate = eventdate; event.eventdate = eventtitle; event.eventinfo = eventinfo; events.add(event); } } class event { public string eventdate { get; set; } public string eventtitle { get; set; } public string eventinfo { get; set; } }
}
bind datagridview bindinglist instead.
code:
public static void addevent(string eventdate, string eventtitle, string eventinfo) { event event = new event(); event.eventdate = eventdate; event.eventdate = eventtitle; event.eventinfo = eventinfo; events.add(event); var bindinglist = new bindinglist<event>(events); var source = new bindingsource(bindinglist, null); grid.datasource = source; }
Comments
Post a Comment