List wpf数据网格集项源列表<;对象>;
我对wpf中的DataGrid有问题 这是一门课:List wpf数据网格集项源列表<;对象>;,list,class,object,datagrid,itemsource,List,Class,Object,Datagrid,Itemsource,我对wpf中的DataGrid有问题 这是一门课: class Superviser { public long Id = 0; public string name = ""; public string father = ""; public string code = ""; } 这是一个函数,用来建立这个类对象的列表 public List<Superviser> allSuperviser()
class Superviser
{
public long Id = 0;
public string name = "";
public string father = "";
public string code = "";
}
这是一个函数,用来建立这个类对象的列表
public List<Superviser> allSuperviser()
{
return db.tbPersons.Where(i => i.level == StaticsObject.isSuperviser).Select(x => new Superviser
{
Id = x.Id,
name = x.firstName,
father = x.father,
code = x.code,
}).ToList();
}
但当运行程序datagrid为空时
提示:列表不是空的
问题在哪里
如何在DataGrid上显示此列表?你好,agian,我解决了它 我换了一个班:
class Superviser
{
public long Id { get; set; }
public string name { get; set; }
public string father { get; set; }
public string code { get; set; }
public Superviser() { }
public Superviser(long Id, string name, string father, string code)
{
this.Id = Id;
this.name = name;
this.father = father;
this.code = code;
}
}
并将功能更改为:
public List<Superviser> allSuperviser()
{
return db.tbPersons.Where(i => i.level == StaticsObject.isSuperviser).Select(x => new Superviser { Id = x.Id, name = x.firstName + " " + x.lastName, father = x.father, code = x.code }).ToList();
}
public List allSuperviser()
{
返回db.tbPersons.Where(i=>i.level==StaticsObject.isSuperviser)。选择(x=>newsuperviser{Id=x.Id,name=x.firstName+“”+x.lastName,father=x.father,code=x.code})。ToList();
}
问题已经解决:)
public List<Superviser> allSuperviser()
{
return db.tbPersons.Where(i => i.level == StaticsObject.isSuperviser).Select(x => new Superviser { Id = x.Id, name = x.firstName + " " + x.lastName, father = x.father, code = x.code }).ToList();
}