DataTable.DefaultView.Sort不排序 [英] DataTable.DefaultView.Sort Doesn't Sort

查看:776
本文介绍了DataTable.DefaultView.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返回一个视图,并给出。表编译错误。

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆