【发布时间】:2010-11-19 16:18:24
【问题描述】:
我有以下业务对象:
public class MyObject
{
// Some public properties that are bound to text boxes, etc on the form
public string Customer { get; set; }
public int JobNumber { get; set; }
// Each DataTable in this list consists of a single column of doubles
// representing the error in a series of measurements (ex. -.0002, -.0003, .0002, etc)
public List<DataTable> MeasurementErrors {get; set; }
public MyObject
{
// Code in here creates the first DataTable with the first measurement (always zero)
// and adds it to the MeasurementErrors list
errors = new DataTable();
errors.TableName = "MeasurementErrors";
errors.Columns.Add("Error", typeof(double));
errors.Rows.Add(0.0);
MeasurementErrors.Add(errors); // initial table added to the list
}
}
我将 Customer 和 JobNumber 以及所有其他基本属性绑定到输入表单上的文本框没有问题(VS 生成了一个 BindingSource 并为我设置了所有这些控件)。
我遇到的问题是将MeasurementErrors 中的一个DataTables 绑定到DataGridView 控件。要绑定的表应该由 NumericUpDown 控件选择,然后将有一个简单的“添加”按钮来生成一个新表并将其添加到 MeasurementErrors(如果需要,还有一个删除按钮)。如何设置 DataGridView 的 DataSource 和 DataMember 属性以绑定到 MeasurementErrors[UpDownControl 的值]?
我并没有固定使用 DataTables,但从我所读到的内容来看,这是绑定到 DataGridView 的首选方式。
【问题讨论】:
标签: c# datagridview bindingsource