c# - why datagridview not showing private property of binded class type -
i have datagridview dgvdtmudetails
show list of class blclsstaffmember
public void showdata() { blclsstaffmember oblclsstaffmember = new blclsstaffmember(); list<blclsstaffmember> listaffmember = new list<blclsstaffmember>(); listaffmember = oblclsstaffmember.getallstaffmember(); dgvdtmudetails.datasource = listaffmember; }
where defination of class is:
public class blclsstaffmember { private int perno { get; set; } private string surname { get; set; } private string forename { get; set; } private string name { get; set; } public list<blclsstaffmember> getallstaffmember() { dtmuentities odtmuentities = new dtmuentities(); return odtmuentities.staff_member.select(s => new { s.perno, s.surname, s.forename }).tolist().distinct().select(s1 => new blclsstaffmember { perno = s1.perno, forename = s1.forename, surname = s1.surname, name = s1.surname + ", " + s1.forename + " [" + s1.perno + "]" }).tolist().distinct().tolist(); } }
the problem is: the datagridview not showing data when property of class marked private
while when properties public datagridview showing data
why?
also in case when use listbox in place of datagridview populating data when properties private.
could please explain
datagrid auto-generates columns, depending on properties of class it's bound to, unless define columns manually.
i'd suggest make properties public , have private fields manipulate data. example:
private string _surname; public string surname { { return _surname; } set { _surname = value; } }
Comments
Post a Comment