有时候我们需要将DataGridView中选择的行存为一个DataTable,这时候就要将DataGridViewRow对象转为DataRow对象。具体做法如下:
DataGridViewSelectedRowCollection rowColl = dataGridView1.SelectedRows;
if (rowColl == null)
return;
DataTable totalDT = (DataTable)dataGridView1.DataSource;
if (totalDT == null)
return;
DataTable gridSelectDT = totalDT.Clone();
for (int i = 0; i < rowColl .Count; i++)
{
DataRow dataRow = (rowColl[i].DataBoundItem as DataRowView).Row;
gridSelectDT.ImportRow(dataRow);
}
本文介绍了一种方法,用于将DataGridView中选定的行转换为DataTable。通过遍历选定的行并将其导入新的DataTable,实现了从DataGridView到DataTable的数据转换。
6213

被折叠的 条评论
为什么被折叠?



