对不包含某些行的数据表进行排序 [英] Sorting a DataTable excluding some rows

查看:93
本文介绍了对不包含某些行的数据表进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个绑定到组合框的城市表.除了该国家最大的城市,我想按字母顺序对它进行排序,并在列表中显示最大的城市.

I have a table of cities that is binded to a combobox. I want to sort it alphabetically except for the biggest city in the country and display the biggest city on top of the list.

dtCities.DefaultView.Sort = "CityName asc";



在某些论坛中,建议使用rowFilter属性.我尝试过,但目的不同.

转:这肯定是一个非常普遍的问题,但不知何故我找不到答案.

rev2:我只是手动将最大的城市插入了组合框的项目列表,并解决了问题.



In some forums it is advised to use rowFilter properity. I tried it but it has a different purpose.

rev: It must be a very common problem but somehow I am unable to find the answer.

rev2: I just inserted the biggest city to the combobox''s items list manually and problem solved.

推荐答案

除了最大的城市",这意味着您必须从结果中过滤掉那个城市. RowFilter用于执行此操作-当您需要结果,..除外"时使用的是

应用过滤器后进行排序,就可以完成.
"Except the biggest city", that means that you''d have to filter that city out of the results. The RowFilter is used to do so - that''s what''s used when you want "results, except.."

Sort after applying the filter, and you''re done.


一种方法可能是:
将一张大城市的桌子和另一张小城市的桌子排序.
形成第三个表,将两个表按顺序合并,然后将第三个表用作组合框的数据源.
One way could be:
Have one table of big cities and other of smaller one sorted.
form a third table merging two in order and use the third one as datasource of your combobox.


这篇关于对不包含某些行的数据表进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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