当列表绑定到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];
.
.
}
&#34; isNew&#34;和&#34; Id&#34;属性正确显示。 我希望得到以下示例输出:
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]);
答案 0 :(得分:0)
试试这段代码:
private void dv_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
if (this.dv.Columns[e.ColumnIndex].Name == "Stage")
{
formatting.Value = //your code to format data for this column;
}
}