0

我正在用一些值填充 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 网格 -

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 的内容相匹配,但会得到空白行。

形式

4

1 回答 1

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; }
}
于 2019-01-15T17:19:36.183 回答