DataTable.DefaultView.Sort不排序 [英] DataTable.DefaultView.Sort Doesn't Sort
问题描述
我对DataTable.DefaultView.Sort感到困惑。以下是我要使用的代码段。
I am confused on DataTable.DefaultView.Sort. Here is the segment of the code I want to use it in.
actionLogDT.DefaultView.Sort = "StartDate";
foreach (CustomerService.ActionLogStartEndRow logRow in actionLogDT)
{
// code here
}
我看到的示例不使用foreach循环,因此令我困惑的是如何处理这个。它不是按照我以为应该排序的。
The samples I have seen don't use the foreach loop and thus is confusing me on how to process this. It isn't sorting as I thought it should be.
我看到这个.DefaultView返回一个视图,而.Table提供了一个编译错误。
I see that .DefaultView returns a view, and .Table gives a compile error.
推荐答案
我不得不采取略有不同的方法。 这篇文章是我找到的最接近我的代码的工作。这是工作结果:
I had to take a slightly different approach. This post was the closest I could find to get my code to work. Here is the working result:
actionLogDT.DefaultView.Sort = "StartDate";
DataView dv = actionLogDT.DefaultView;
foreach (DataRowView logRow in dv) { . . . }
从那里我只需要将值重新转换成正确的类型。
From there I just have to cast the value back into it's proper type.
(string)logRow["Status"].ToString()
这篇关于DataTable.DefaultView.Sort不排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!