前提条件:
DataGridView控件,绑定的是DataTable。
目的:
把DataGridView控件中选中的行,保存到DataTable中
解决方法:
DataTable m_SourceDT = DataGridView1.DataSource as DataTable;
DataTable m_DT = m_SourceDT.Clone();//克隆表格的结构
DataGridViewSelectedRowCollection m_SRS = DataGridView1.SelectedRows;
foreach(DataGridViewRow item in m_SRS)
{
//转换成数据行DataRow
DataRow dataRow = (item.DataBoundItem as DataRowView).Row;
m_DT.ImportRow(dataRow);
}