【发布时间】:2017-10-27 16:58:32
【问题描述】:
我正在使用名为ClearSCADA 的施耐德产品,它允许您通过.Net 接口查询其专有的后端数据库。我已经使用这个查询成功地查询了数据库:
SELECT
"Id", "FullName", "Foreground", "Blink", "Background", "TypeDesc", "MemoryUsage"
FROM
"CCustomColour"
ORDER BY
"FullName" ASC
并将结果作为 QueryResult 返回给我:
using System.Collections.ObjectModel;
namespace ClearScada.Client.Advanced
{
//
public class QueryResult
{
//
// Summary:
// Gets the results of the query.
public ReadOnlyCollection<QueryRow> Rows { get; }
//
// Summary:
// Gets the number of rows affected for a DML query.
public int RowsAffected { get; }
//
// Summary:
// Gets the status of the query.
public QueryStatus Status { get; }
}
}
我尝试通过几种不同的方式将行的ReadOnlyCollection 绑定到数据网格。
dataGridViewResults.DataSource = this.MyQueryResult.Rows;
和
BindingSource bs = new BindingSource();
bs.DataSource = this.MyQueryResult.Rows;
dataGridViewResults.DataSource = bs;
网格向我显示了一个仅显示行索引但没有数据的列:
这里是 QueryRow 类的定义供参考:
using System.Collections.ObjectModel;
namespace ClearScada.Client.Advanced
{
//
public class QueryRow
{
//
public ReadOnlyCollection<object> Data { get; }
//
public int Index { get; }
}
}
我创建了我的 QueryResult 实例的本地副本,以便我可以在 Visual Studio 的“本地”窗口中捕获它的视图以显示在这里:
我想要实现的是这样显示的视图:
您能帮我看看如何将这些值绑定到 DataGridView 吗?
【问题讨论】:
标签: c# .net datagridview binding