c# - Datagridview and properties to Contained Objects -


i have bindinglist of objects. objects contain public properties displayed databindingview. unfortunately can't properties return field data of contained objects work. take instance contrived example below:

public class chimpdiet {   public string favoritefood; }   public class chimpanzee {   private chimpdiet diet;    [displayname("chimp's favorite food")]   public string favoritefood   { { return diet.favoritefood; } }    [displayname("chimp's nickname")]   public string nickname { get; set; }    public chimpanzee()   {     diet = new chimpdiet();   }  } 

when set bindinglist of chimpanzees datasource of datagridview, property favoritefood causes errors pop up:

the following exception occurred in datagridview:
system.reflection.targetinvocationexception: property accessor.... threw following exception: 'object reference not set instance of object.'.....

made sure instance created in constructor of container object, doesn't fix problem. suggestions? on net 2.0

p.s. data displayed grid, error keeps popping saying reference not set instance, though is. must winforms problem.

update: changing chimpdiet class struct removes errors. need class. makes no sense me.

ok, turns out datagridview wants contained object have default constructor (no arguments) initializes every single 1 of field data. don't know why (if shed light on this, please do) program working, that's that.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -