我希望此函数在调用时显示在数据网格视图中
private DataTable resetColumnsOrder(DataTable dataTable,string[] selectedQuarters)
{
try
{
List<string> colNames = new List<string>();
int startIndex = 0; int x = 0;
string[] columnNames = (from dc in dataTable.Columns.Cast<DataColumn>()
select dc.ColumnName).ToArray();
foreach(string quarter in selectedQuarters)
{
if (quarter == "All")
continue;
if(Array.Exists<string>(columnNames, s => s.StartsWith(quarter + "¢")))
{
string firstE = Array.Find<string>(columnNames, s => s.StartsWith(quarter + "¢"));
string [] qElements = Array.FindAll<string>(columnNames, s => s.StartsWith(quarter + "¢"));
startIndex = Array.FindIndex<string>(columnNames, s => s == firstE);
if (x == 0)
{
for (int i = 0; i < startIndex; i++)
{
colNames.Add(columnNames[i]);
}
}
colNames.AddRange(qElements);
}
x++;
}
colNames.Add("Grand Total");
dataTable.SetColumnsOrder(colNames.ToArray());
dataTable.AcceptChanges();
}
catch (Exception ex)
{
LogErrorService.LogError("Error in method (resetColumnsOrder) - " + ex.Message.ToString());
}
return dataTable;
}