[英]How to Binding the array[] to the DataGridTextColumn dynamiclly wpf
When I have a Staff class ,I want to Binding the TB[] to the DataGrid Columns Staff.cs 当我有一个Staff类时,我想将TB []绑定到DataGrid列Staff.cs
public class Staff
{
public string Name { get; set; }
public float? Test_Score { get; set; }
public float? Net_Income_Tax { get; set; }
public float temp { get; set; }
public float[] TB = new float[100];
public float TB_Sum { get; set; }
}
in the Page,my code are as follows: 在页面中,我的代码如下:
public ObservableCollection<Staff> Staff_Show = new ObservableCollection<Staff>();
public int StaffShowSize;
public TaxBefore_Sum(ObservableCollection<Staff> StaffAccept)
{
InitializeComponent();
Staff_Show = StaffAccept;
StaffShowSize = Staff_Show.Count;
DataGrid1.ItemsSource = this.Staff_Show;
//this is to dynamiclly to create new DataGridTextColumn,but
//final ,only create the columns' header is"0",and no data to show,however,the TB[i] have data,but can't show like the picture
for (int i = 0; i < StaffShowSize; i++)
{
DataGridTextColumn c = new DataGridTextColumn();
c.Header = Convert.ToString(i + 1);
c.Binding = new Binding("TB[i]");
DataGrid1.Columns.Add(c);
}
}
the "for()" sentence is to dynamiclly to create new DataGridTextColumn,but final ,only create the columns' with header,and no data to show,however,the TB[i] have data,but can't show like the picture: “ for()”语句是动态创建新的DataGridTextColumn,但最终只能创建带有标题的列,并且没有要显示的数据,但是TB [i]有数据,但是不能像图片一样显示:
when I changed the code to 当我将代码更改为
c.Binding = new Binding("TB[" + i + "]");
Here is what you need... 这是您需要的...
c.Binding = new Binding("TB[" + i + "]");
Also definition of TB... 还定义了结核病...
public float[] TB { get; set; } = new float[100];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.