使用虚模式,将DataGridView的VirtualMode属性设置为true,
private void dgReport_CellValueNeeded(object sender, DataGridViewCellValueEventArgs e)
{
DataRow dr = DTData.Rows[e.RowIndex];
for (int i = 0; i < DTData.Columns.Count; i++)
{
if (e.ColumnIndex == i)
{
e.Value = dr[i];
}
}
}
DataGridView和DataTable清空,添加行的顺序必须不能弄反,否则会出问题
dgReport.Rows.Clear();
DTData.Clear();
DTData.Columns.Clear();
DTData.Rows.Add();
dgReport.Rows.Add();