dataTable.Columns["Qty"].SetOrdinal(0); dataTable.Columns["Unit"].SetOrdinal(1);
扩展方法:
public static class DataTableExtensions { public static void SetColumnsOrder(this DataTable table, params String[] columnNames) { int columnIndex = 0; foreach(var columnName in columnNames) { table.Columns[columnName].SetOrdinal(columnIndex); columnIndex++; } } }
用法:
table.SetColumnsOrder("Qty", "Unit", "Id");
或
table.SetColumnsOrder(new string[]{"Qty", "Unit", "Id"});
标签:SetColumnsOrder,更改,c#,SetOrdinal,Qty,table,DataTable,Columns From: https://www.cnblogs.com/firstcsharp/p/17826487.html