Rashmi S Rashmi S - 9 months ago 114
C# Question

Convert dataRowview to dataTable in c#

I am trying to convert dataRowview into Datatable:

private void Cell_Edit_End(object sender, DataGridCellEditEndingEventArgs e)
{
DataRowView rowView = e.Row.Item as DataRowView;
rowBeingEdited = rowView;
}
DataTable dt = new DataTable();
foreach (DataRow row in rowBeingEdited.Row.GetChildRows) {
dt.ImportRow(row);
}


Can anyone help me to solve.

Answer Source

We can directly convert dataRowview into Datatable as:

 DataTable dt = rowBeingEdited.DataView.ToTable();