针对题目目的,对于读入的数据进行操作如下
//读取前先清除内容
for (int i = 0; i < dataGridResult.RowCount - 1; i++)
{
dataGridResult.Rows.RemoveAt(i);
}
//中间对dataGrid执行某种操作,可能产生空行
for (int i = 0; i < ScoreSelect.Count; i++)
{
dataGridResult.Rows.Add();
dataGridResult.Rows[i].Cells[0].Value = NameSelect[i];
}
//再删除表中空白行
for (int i = 0; i < dataGridResult.Rows.Count - 1; i++)
{
if (dataGridResult.Rows[i].Cells[0].Value == null)
{
dataGridResult.Rows.RemoveAt(i);
}
}