c# - XtraGrid binding inherited object -
i have 1 base class , 2 inherited classes. according configuration of application must bind customer1 or customer2 xtragrid:
public abstract class mybase { public int itemid { get; set; } } public class customer1 : mybase { public string name { get; set; } public datetime birthdate { get; set; } } public class customer2 : mybase { public string name { get; set; } } now, binding code:
customer1 c1 = new customer1(); c1.itemid = 1; c1.name = "n1"; c1.birthdate = datetime.now; bindinglist<mybase> tmplist = new bindinglist<mybase>(); tmplist.add(c1); gridcontrol1.datasource = tmplist; but grid display itemid field derived mybase class.
could pls help?
thanks.
the simple answer - cannot that. not specific xtragrid, controls use list data binding. when use list<t>, bindinglist<t> etc. typeof(t) extracted , used item type retrieve bindable properties. note none of these classes (and ilist<t> in general) supports variance, cannot use base class generic parameter. use concrete class when instantiating list/bindinglist plan use data source (in case - bindinglist<customer1> or bindinglist<customer2>).
Comments
Post a Comment