c# - Binding a DataGridView to a Object list -


i'm new databinding in .net , want bind datagridview object list. grid may populate in 2 ways.

there textboxes in form , users can enter text , when press add button new object instantiated provided fields , added list.

other way is, when user searches objects, matching objects loaded database list. after searching users should able add new items list in first method.

finally list binded datagridview , user changes items shown in grid , if it's right, user save them.

so in presenter have 3 methods above requirements.

class attendancepresenter  {     private void addattendance()     {         attendancelist.add(attendancemodel);         var bindinglist = new bindinglist<iattendance>(attendancelist);         var source = new bindingsource(bindinglist, null);         _view.attendancegrid = source;     }       private void getattendance()     {         attendancelist = _dataservice.getattendance();         var bindinglist = new bindinglist<iattendance>(attendancelist);         var source = new bindingsource(bindinglist, null);         _view.attendanceingrid = source;     }      private void save()     {         _dataservice.insertattendance (attendancelist);     }  } 
  1. i'm not sure way i've binded things right. , wonder if use single binding list here i'm binding same list same datagridview! possible?

  2. whats difference of using bindingsource along , bindinglist, in context?

bind datagridview presenters attendancelist right in constructor, assuming view instantiated @ point. in presenter this:

class attendancepresenter  {     private readonly bindinglist<iattendance> _attendancelist;      public attendancepresenter()     {         _attendancelist = new bindinglist<iattendance>();         _view.attendancegrid = _attendancelist;     }      private void addattendance()     {         _attendancelist.add(attendancemodel);     }      private void getattendance()     {         _attendancelist.clear();          var attendance = _dataservice.getattendance();          foreach (var attendant in attendance)         {             _attendancelist.add(attendant);         }     }      private void save()     {         _dataservice.insertattendance (_attendancelist);     } } 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -