c# - 除了满足条件的行,如何对 DataTable 进行排序?
问题描述
我试图DataTable
在 C# 中按特定顺序对 a 进行排序,它的特殊之处在于,如果满足给定条件,我需要一些行保留在原始位置。
我目前正在使用这个功能:
OriginalTable.DefaultView.Sort = "[column_name] ASC";
包含没有数据的OriginalTable
行,我需要保留这些行,而其他行按 ASC 条件排序。任何可能有助于解决这个问题的想法?
提前致谢!。
解决方案
我不知道结构。而且我确信没有直接的方法可以满足您的要求。只是想在这里给出指针/伪代码。
Step 1: Create a dictionary(Key-value) for the rows which met your condition. Ensure to keep the index of the item in the key
Step 2: Create a list with rows which do not met your condition. Then sort it
Step 3: Insert the rows from step 2 into your datatable one by one checking the index. If you find the index in step 1 rows, insert it at that location
我希望它有帮助
推荐阅读
- r - 有没有办法根据另一个变量的第一个字母创建一个逻辑变量?
- excel - 计算具有子字符串的合并单元格
- audio - 音频比特率变化对频谱图的影响
- android - 好像有错误,没有
- r - 尝试在 R 中使用单独()函数时在 UseMethod 中出现错误
- javascript - 即使使用空括号,如何修复 React 的 useEffect 无限循环?
- javascript - JavaScript 以编程方式检查是否正在使用相机
- html - 如何获取图像高度并将该高度赋予图像 div 以使其响应
- mysql - MYSQL - 无法添加外键约束,但为什么呢?
- asp.net-mvc - Razor 默认使用 SignalR 吗?