如何对符合条件的行以外的数据表进行排序?

时间:2018-08-30 22:32:23

标签: c# sorting datatable

我正在尝试以某种顺序在C#中对DataTable进行排序,这很特别,那就是如果满足给定条件,我需要将某些行保留在原始位置。

我当前正在使用此功能:

OriginalTable.DefaultView.Sort = "[column_name] ASC";

OriginalTable包含没有数据的行,我需要保留这些行,而其他行则按ASC条件进行排序。有什么想法可以解决这个问题吗?

提前谢谢!。

1 个答案:

答案 0 :(得分:0)

我不知道结构。而且我敢肯定没有直接的方法可以满足您的要求。只是尝试在此处提供指针/伪代码。

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

我希望对您有帮助