I tried saving the datatable rows to a datarow[] array then deleting the datatable rows and rewrite them to the datatable from the datarow[] array in a different order. But when I delete them from the datatable I can’t access them from the datarow[] array.
I don’t know if I’m doing this correct or if im totally off base but I’m in desperate need of help.
This is what I’m trying to do:
I have a datatable with 8 rows.
I want to be able to somehow loop thru the 8 rows and reorder them based on certain criterias.
For example, my rows have an Invoice number, line number, and Part number as the key fields. Depending on the criteria, I may need rows 6,7,8 to be in the beginning as rows 1,2,3 and shift the rest down.
If anyone has an Idea please reply….this is an urgent issue.
thank you,
Sam
If you take a DataRow:
and then delete the row from the table,
drwill also be deleted. It’s the same row. That explains your problem.As for the solution, don’t reorder rows in a DataTable. Instead, add another column called
RowOrder, modify it to change the order, and then sort the DataTable based on that column, as @mperrenoud03 has shown you:table.DefaultView.Sort = “RowOrder”;
and use the default view.