Binding datagrid to list of custom object using BindingList
hi,
i have used 3 tire methodology, in data access layer have created customer class , other support classes handle & encapsulate data customer table, insert , update & delete records database . when move data data access layer bll have used list of customer objects.
in same manner in bll have class customerbll which contain definition of customer object , static & instance methods call related static & instance of data access layer , these method can list of records , convert list of customerbll objects , contain method handle insert , update & delete.
in ui layer have used static method of customerbll objects list of customer objects (mylist )
list<customerbll> mylist = customerbll.getcustomerbyname("h", 0, int.maxvalue);
and because ilist not support add new / update data grid have converted binding list:
bindinglist<customerbll> mybindinglist = new bindinglist<customerbll>(mylist);
then have used binding list data soruce datagrid
datagridview1.datasource = mybindinglist;
in datagridview1 have added 2 buttons 1 delete , 1 update , inside buttons have called static method of customerbll handle delete & update on database.
only add new row in datagrid i'm facing problem , when user add new row in datagrid not able find event should use call the static method of customerbll handle insert in db, have tried following events, giving error either because been called when row created , user not entered data in gridview :
rowsadded
rowleave
currentcellchanged
useraddedrow
i know after user enter data in new row which event can use handle add new , in event call insert method of customerbll insert record in database.
thanks
hi jason,
actually doing r&d on binding list of custom objects datagrid, face issue mentioned in my query , on high level current finding need implement ibindinglist interface , ieditableobject interface. decided read more interfaces before apply solution.
once complete reading share more details solution. there 2 examples in msdn about implementing the ibindinglist interface , ieditableobject interface need extended include direct encapsulate database tables.
http://msdn.microsoft.com/en-us/library/system.componentmodel.ieditableobject.aspx
http://msdn.microsoft.com/en-us/library/system.componentmodel.ibindinglist.aspx
humam
thanks
Visual Studio Languages , .NET Framework > Visual C#
Comments
Post a Comment