我正在用一些值填充DataTable(在定义列名之后),然后将其用作Sage Grid的数据源-功能上与WinForms DataGridView非常相似。
到目前为止,我已经尝试将数据类型添加到DataTable列,并使用DataTable填充BindingSource,然后将其绑定到Sage Grid。在调试时查看DataTable的内容时,可以使用DataSet Visualiser看到数据在那里。
创建数据表-
DataTable failedOrders = new DataTable();
failedOrders.Columns.Add("externalItemCodeColumn", typeof(String));
failedOrders.Columns.Add("reasonColumn", typeof(String));
foreach (String item in insufficientItemsAvailable)
{
DataRow dataRow = failedOrders.NewRow();
dataRow["externalItemCodeColumn"] = item;
dataRow["reasonColumn"] = "Not enough available items in WAREHOUSE";
failedOrders.Rows.Add(dataRow);
}
填充贤者网格-
Sage.Common.Controls.GridColumn externalItemCodeColumn = new Sage.Common.Controls.GridColumn();
externalItemCodeColumn.Caption = "External Item Code";
externalItemCodeColumn.DisplayMember = "externalItemCodeColumn";
Sage.Common.Controls.GridColumn reasonColumn = new Sage.Common.Controls.GridColumn();
reasonColumn.Caption = "Reason";
reasonColumn.DisplayMember = "reasonColumn";
failedOrdersGrid.Columns.Add(externalItemCodeColumn);
failedOrdersGrid.Columns.Add(reasonColumn);
failedOrdersGrid.DataSource = FailedOrders;
//failedOrdersGrid.Refresh(); - this doesn't seem to make a difference
请注意,failedOrders传递给了另一个方法,因此名称从failedOrders更改为FailedOrders。
只是为了检查这种行为是否不特定于Sage Grid,我尝试用DataTable填充常规WinForms DGV。 (注意-我禁用了AutoGenerateColumns,因为这似乎不是Sage Grid的选项。)
dataGridView1.AutoGenerateColumns = false;
dataGridView1.Columns.Add("externalItemCodeColumn", "External Item Code");
dataGridView1.Columns.Add("reasonColumn", "Reason");
dataGridView1.DataSource = FailedOrders;
我希望Sage Grid的内容与DataGrid的内容匹配,但是会得到空白行。
答案 0 :(得分:1)
Sage.Common.Controls.Grid继承自Sage.Common.Controls.List和Sage.Common.Controls.List的DataSource属性,刷新时要求新的DataSource支持至少IList (实际上,它不是IList只会使您的数据源无效)
这是您的代码的改编版,可与Sage.Common.Controls.Grid一起使用
我将其添加到表单的构造函数中(failedOrdersGrid类型为Sage.Common.Controls.Grid):
List<Failure> failedOrders = new List<Failure>();
foreach (String item in new List<string> { "1", "2", "3" })
{
failedOrders.Add(new Failure { externalItemCodeColumn = item, reasonColumn = "Not enough available items in WAREHOUSE" });
}
Sage.Common.Controls.GridColumn externalItemCodeColumn = new Sage.Common.Controls.GridColumn();
externalItemCodeColumn.Caption = "External Item Code";
externalItemCodeColumn.DisplayMember = "externalItemCodeColumn";
Sage.Common.Controls.GridColumn reasonColumn = new Sage.Common.Controls.GridColumn();
reasonColumn.Caption = "Reason";
reasonColumn.DisplayMember = "reasonColumn";
failedOrdersGrid.Columns.Add(externalItemCodeColumn);
failedOrdersGrid.Columns.Add(reasonColumn);
failedOrdersGrid.DataSource = failedOrders;
这是失败类:
public class Failure
{
public string externalItemCodeColumn { get; set; }
public string reasonColumn { get; set; }
}