问题描述
我有一个雇员列表:
Person类具有两个属性:
每个小时(最多24小时)制作的小部件的名称和数量列表
the class Person has two properties:
a name, and a List-of number of widgets they made each hour(limited to 24 hours)
现在我想在datagridview中显示此数组:我想显示应该看起来像这样:
Now i want to display this array in a datagridview: i guess the display should look something like:
employees, 1,2,3,4,....,24
anna , 0,10,5,15,..,5
jeff , 1,6,2,......,4
以此类推.
现在,我只是使datasource = employees绑定,这成功显示了名称,但它甚至没有触及List属性.将属性列表做成整数列表有什么技巧吗?还是我应该每小时为列表创建一个单独的属性?
right now i just make a datasource=employees binding, and this sucessfully displays the name, but it doesn't even touch the List property. is there some trick to making a list of ints into a property? or maybe i should make a separate property for each hour that will interface with the list?
推荐答案
一个简单的选择是在 Person
类内创建一个"get"属性,该属性将整数列表作为单个字符串返回,就像你想输出.
a simple option is to create a "get" property inside the Person
class that returns the list of integers as a single string, like you want to output.
public string NumbersList
{
get
{
return string.Join(", ", this.List);
}
}
当您绑定时,请使用此属性而不是列表,这样它将显示您想要的长字符串("1、3、4")
and when you bind, use this property instead of the list so it will show the long string you want ("1,3,4")
这篇关于datagridview中的列表清单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!