我有以下代码:
DataTable table = new DataTable();
//DataTable is filled with values here...
DataGridView grid = new DataGridView();
foreach (DataColumn column in table.Columns)
{
grid.Columns.Add(column.ColumnName, column.ColumnName);
}
grid.DataSource = table;
当我检查时grid
, the DataSource
属性表明行数是正确的。但是,那grid.Rows
计数为零。
相反,如果我创建一个DataGridView
在winform上,然后分配它的DataSource
to a DataTable
, the DataGridView.Rows
将会自动添加。
我在这里缺少什么代码才能获得DataGridView.Rows
数对了吗?
通过添加这个DataGridView
以编程方式控制表单,它可以工作:)
有人能告诉我们为什么吗?
DataTable table = new DataTable();
//DataTable is filled with values here...
DataGridView grid = new DataGridView();
// assuming (this) is a reference to the current form
this.Controls.Add(grid);
grid.DataSource = table;
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)