2016-04-25 44 views
0

当列表绑定到DataGridView时,是否有方法从数组属性显示格式化的字符串?从DataGridView中的数组显示格式化的字符串DataSource

我目前使用下面的代码:

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]; 
    . 
    . 
} 

无论是“是否新款”和“ID”属性显示正常。 我希望得到下面的示例输出:

IsNew | Id | Stage 
[✓]  1  1/5/7/9 
[ ]  2  2/3/8/9 
[ ]  3  3/5/8/10 

,其中第一阶段是格式化为

string.Format("{0}/{1}/{2}/{3}", Stage[0], Stage[1], Stage[2], Stage[3]); 
+2

你可以使用CellFormatting或公开只返回格式化数据的只读属性 – Plutonix

回答

0

4个元素的数组试试这个代码:

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; 
    } 
} 
相关问题