将 list<object> 的数组绑定到二维 datagridview
Binding array of list<object> to 2-dimensional datagridview
我正在尝试绑定 Master_Transaction_List,这是一个列表数组到数据网格视图。目前,当 list[] 在 运行 时绑定到 datagridview 时只显示一列(而且它似乎是每行的列数,而不是实际数据)。
dh.Fill_Master_Transaction_List("SELECT * FROM transactions_dumpfile WHERE Tran_Price=8000;");
dataGridView1.DataSource = dh.Master_Transaction_List;
Class dh 根据这个查询,用 MySQL table 中的相关数据填充一个名为 Master_Transaction 的 public list[] 列表。我可以看到查询 运行ning 很好,我的 list[] 数组是我想要的正确的二维数据集; 16 列,~1k 行。
但是当我为数据网格设置数据源时,只显示一列;显示的不是数组每个成员的列表项中的数据,而是数组每个成员(即每个列表中)的列数。
问题可能是我对每个数组成员中的所有对象使用 'object' 数据类型吗? datagridview 对此敏感吗?我需要提前为它提供列的架构吗?
编辑:要清楚,这是 dh:
中 Master_Transaction_List 的定义
public List<object>[] Master_Transaction_List;
来自MSDN
The DataGridView class supports the standard Windows Forms
data-binding model.This means the data source can be of any type that
implements one of the following interfaces:
The IList interface,
including one-dimensional arrays.
The IListSource interface, such as
the DataTable and DataSet classes.
The IBindingList interface, such as
the BindingList class.
The IBindingListView interface, such as the
BindingSource class.
尝试将外部数组转换为列表,将内部列表转换为数组。根据那个数组列表是可以的
我正在尝试绑定 Master_Transaction_List,这是一个列表数组到数据网格视图。目前,当 list[] 在 运行 时绑定到 datagridview 时只显示一列(而且它似乎是每行的列数,而不是实际数据)。
dh.Fill_Master_Transaction_List("SELECT * FROM transactions_dumpfile WHERE Tran_Price=8000;");
dataGridView1.DataSource = dh.Master_Transaction_List;
Class dh 根据这个查询,用 MySQL table 中的相关数据填充一个名为 Master_Transaction 的 public list[] 列表。我可以看到查询 运行ning 很好,我的 list[] 数组是我想要的正确的二维数据集; 16 列,~1k 行。
但是当我为数据网格设置数据源时,只显示一列;显示的不是数组每个成员的列表项中的数据,而是数组每个成员(即每个列表中)的列数。
问题可能是我对每个数组成员中的所有对象使用 'object' 数据类型吗? datagridview 对此敏感吗?我需要提前为它提供列的架构吗?
编辑:要清楚,这是 dh:
中 Master_Transaction_List 的定义public List<object>[] Master_Transaction_List;
来自MSDN
The DataGridView class supports the standard Windows Forms data-binding model.This means the data source can be of any type that implements one of the following interfaces:
The IList interface, including one-dimensional arrays.
The IListSource interface, such as the DataTable and DataSet classes.
The IBindingList interface, such as the BindingList class.
The IBindingListView interface, such as the BindingSource class.
尝试将外部数组转换为列表,将内部列表转换为数组。根据那个数组列表是可以的