【发布时间】:2015-07-12 06:35:11
【问题描述】:
我正在尝试从 datagridview 中选择一组行并通过单击按钮对其进行更新以仅在同一视图中显示所选信息,这是我目前拥有的代码:
private void btnUpdate_Click(object sender, EventArgs e)
{
List<DataGridViewRow> rowCollection = new List<DataGridViewRow>();
foreach (DataGridViewRow row in dataGridView1.SelectedRows) {
rowCollection.Add(dataGridView1.Rows[row.Index]);
}
dataset.Tables[0].Clear();
foreach (DataGridViewRow row in rowCollection)
{
DataRow r = dataset.Tables[tableName].NewRow();
//write the data in the DataRow and then add the datarow in your datatable
dataset.Tables[tableName].Rows.Add(r);
}
}
按下更新按钮后没有错误并且选择的行数是正确的,但网格视图中没有显示任何信息,感谢任何帮助,干杯!
【问题讨论】:
标签: c# datagridview datasource