DataView.ToTable() 是否保持降序排序?
我在对数据表进行排序时遇到问题。 我使用 DataView.Sort
然后使用 DataView.ToTable()
来获取排序后的表。 然后,我逐行浏览表格,并在桌面应用程序中显示的 TreeView 中创建节点。
我的问题是,我可以按升序对数据进行排序,并且它以正确的方式显示在 TreeView 中,但是当我使用相同的排序机制但只是将顺序更改为降序时,它不起作用。
但问题可能出在 DataView.ToTable 函数上。 这是否保持降序,或者当我通过以相反的顺序遍历 DataRows 在 TreeView 中创建节点时,我是否必须自己修复此问题?
希望有人知道这一点。
I have a problem with sorting a DataTable.
I'm using DataView.Sort
and then DataView.ToTable()
to get the sorted table.
Then I go through the table row by row and create nodes in a TreeView which is shown in a desktop application.
My problem is that I can sort the data in ascending order and it is shown in the TreeView in a correct way, but when I use the same sort mechanism but just change the order to descending it doesn't work.
But maybe the problem lies in the DataView.ToTable
function. Does this keep a descending order or do I have to fix this myself when I create nodes in my TreeView by going through the DataRows in reverse order?
Hoping someone knows this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我找到了问题的答案!
问题只是我对两列进行了排序,如下所示:
“ColumnA,ColumnB DESC”,直到现在我才意识到“DESC”部分仅适用于第二列。 -我真傻。
但无论如何还是谢谢你的回复。 在单步执行 DataView 时我将使用这种方法。
/伊尔瓦
I found the answer to my problem!
The problem was just that I did the sorting on two columns, like this:
"ColumnA, ColumnB DESC" and I didn't realize until just now that the "DESC" part would only apply to the second column. -Silly of me.
But thanks for the reply anyway. I will use that approach when stepping through the DataView.
/Ylva
为什么不使用 DataView 来迭代行? 从您的问题来看,我认为没有必要将排序的内容从一个表复制到另一个表。 请记住,数据视图只是排序和过滤的表表示。
所以你应该写这样的东西:
而不是
Why you are not using DataView for iterate rows? From your question I do not see necessity in copying sorted content from one table to another table. Remember that data view is just sorted and filtered table representation.
So you should write something like this:
instead of