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屋!