有一个叫的课程DisplayTable。以后绑定到一些观察Collection,然后将值填充到datatable。
我需要表的value列应仅接受整数,小数,双精度。
public class DisplayTable
{
public string AnalyteName { get; set; }
public string Units { get; set; }
[RegularExpression(@"0-9+(.)", ErrorMessage="This field accept Only numeric values")]
public float ReferenceValue { get; set; }
}
//Binding the class to Collection
public ObservableCollection<DisplayTable> list { get; set; }
// creating an istance to the class
DisplayTable d = new DisplayTable();
d.AnalyteName ="c"
d.Units= "mg"
this.list.Add(d)
table.Columns.Add("Analyte Name");
table.Columns.Add("Units");
table.Columns.Add("Value");
foreach (var item in this.list)
{
drn = table.NewRow();
int col = 0;
drn[col] = item.AnalyteName ;
drn[col + 1] = item.Units;
drn[col + 2] = item.ReferenceValue;
table.Rows.Add(drn);
table.AcceptChanges();
}
dataGrid.ItemsSource = table.DefaultView;
繁星coding
相关分类