[英]using a C# list as datasource of datagridview (Winform)
the question says it all , i want to use a list as a datasource and i wrote the code below : 这个问题说明了一切,我想使用列表作为数据源,并且我在下面编写了代码:
var uname = DB.TBL_USAGE.Where(x => x.UName != null).ToList();
List<usage> lst = new List<usage>();
foreach (var item in DB.TBL_USAGE)
{
lst.Add(new usage { uname = item.UName, bytesout = item.Bytesout });
}
var bndngsrc = new BindingSource();
bndngsrc.DataSource = lst;
dataGridView1.DataSource = bndngsrc;
and this is the class : 这是课程:
public class usage
{
public string uname;
public string bytesout;
}
but no luck ! 但是没有运气!
can any one present a code that works or correct my code ? 任何人都可以提供有效的代码或更正我的代码吗?
var uname = DB.TBL_USAGE.Where(x => x.UName != null).ToList();
List<usage> lst = new List<usage>();
foreach (var item in DB.TBL_USAGE)
{
lst.Add(new usage { uname = item.UName, bytesout = item.Bytesout });
}
dataGridView1.DataSource = lst ;
\\ \\
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.