Click here to Skip to main content
15,867,686 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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";


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.
Posted
Updated 28-Jul-10 1:00am
v3

"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.
 
Share this answer
 
Comments
Emre Gönültaş 28-Jul-10 5:36am    
It does not work! When I apply the filter other rows disappear.
Eddy Vluggen 28-Jul-10 5:51am    
How does the code of your filter look? Code would go along these lines;
view.RowFilter = "City = 'Berlin'";
view.Sort = "City DESC";
Emre Gönültaş 28-Jul-10 6:01am    
It looks exactly like yours. The RowCount drops to 1. Only Berlin remains.
dtCities.DefaultView.RowFilter = "CityName = 'Istanbul'";
dtCities.DefaultView.Sort = "CityName asc";
Eddy Vluggen 28-Jul-10 6:04am    
dtCities.DefaultView.RowFilter = "CityName 'Istanbul'";

..and how many records are in that dataset with that particular CityName? :)
Emre Gönültaş 28-Jul-10 6:42am    
Sorry for late response.
Only 1 since it is nothing but the list of Cities. What did you mean?
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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900