.net - Binding a combobox with a list of class having public variables -
this concept cannot understand. have class
    class employee     {     public int id;     public string name;     }      list<employee> lst = new list<employee>();                 employee o = new employee();                 o.id = 1;                 o.name = "darshan";                 lst.add(o);                 employee o1 = new employee();                 o1.id = 2;                 o1.name = "gopal";                 lst.add(o1);     combobox1.displaymember = "name";         combobox1.valuemember = "name";         combobox1.datasource = lst; the above doesn't work. when change public fields , set, works.
is there way can bind without , set properties?
public fields accessible outside class. can read , write value of field anywhere. why can't use them in binding? why use properties?
if @ documentation:
displaymember property:gets or sets property display system.windows.forms.listcontrol.
when add get , set fields become properties.and displaymember , valuemember looks property named "name" in class.not field.without get , set have fields cannot use bindings that.see question more details properties , fields: what difference between field , property in c#?
Comments
Post a Comment