I am writing a search form for desktop application and I have a problem with combobox binding.
The user can search for properties by various criteria (city, price, etc).
I want to bind combobox to list of all possible cities, but I want to leave the user the option not to choose anything so it can search properties in all cities.
How can I do that?
I'm using linq2sql for data access.
views:
255answers:
1
A:
Well, supposing you have bound the combobox to a List of Cities that you pulled from your database:
class City
{
public string ID{get; private set;}
public string Name{get;private set;}
public City(string id, string name)
{
ID=id;Name=name;
}
}
Just Add an empty city to that list:
cityList.Add(new City("AA",string.empty");
When you bind the combobox to the cityList and sort it, the city with id "AA" will be on top. In your searching code you can now adjust your search algorithm for the case that the user has selected the city with id "AA";
Cleverer solutions are certainly possible, but I would need to see some code of the searching method to help you further.
Dabblernl
2009-10-25 14:07:17