【发布时间】:2016-04-25 15:20:42
【问题描述】:
有没有办法在列表绑定到 DataGridView 时显示来自数组属性的格式化字符串?
我目前正在使用以下代码:
var bindingList = new BindingList<Stage>(stageList);
var source = new BindingSource(bindingList, null);
dv.DataSource = source;
dv.AutoGenerateColumns = true;
internal class Stage
{
.
public bool isNew {get; protected internal set; }
public int Id { get; protected internal set; }
public short[] Level { get; protected internal set; } = new short[4];
.
.
}
“isNew”和“Id”属性都正确显示。 我希望得到以下示例输出:
IsNew | Id | Stage
[✓] 1 1/5/7/9
[ ] 2 2/3/8/9
[ ] 3 3/5/8/10
其中 Stage 是一个包含 4 个元素的数组,格式为
string.Format("{0}/{1}/{2}/{3}", Stage[0], Stage[1], Stage[2], Stage[3]);
【问题讨论】:
-
您可以使用 CellFormatting 或公开一个返回格式化数据的只读属性
标签: c# winforms data-binding datagridview datasource