to add an ALL selection in the bound combo box?

samiullah478

New member
Joined
Dec 15, 2006
Messages
2
Programming Experience
Beginner
i want to know a thing that i bound a combo box to database field. but i also want to give a selection of ALL items and place a selection of ALL in the combo box how to do this plz guide me?:eek:
 
There is no control built in to do this i'm afraid. It's a question i've seen quite a bit on here and i've always failed to find one on the web which leads me to believe that it must be quite hard to do.
 
I did something like this for a databound combobox:

MS SQL/Server:
Select 0 as make_id, ' ALL' as make_description
Union
Select make_id, make_description
From automobile_makes
Order by make_desc;

Oracle:
Select 0 as make_id, ' ALL' as make_description From dual
Union
Select make_id, make_description
From automobile_makes
Order by make_desc;

I used a leading space in ' ALL' so that it would show up as first item.

HTH
 
note, use of UNION ALL may be quicker.. in this casee it shouldnt matter too much because the number of entries in the combo will be less than 20 if good hci practices are observed..
 
im not sure about this, as i usually dont work with databound controls, but after binding the dataset, couldn't you just add an item called 'ALL' at the index of 0? and on the selectedindexchanged event if the selectedindex is 0, run the 'all' query (or whatever you want to do).

or you could just not bind the combobox, but still chuck in the values you need (from the dataset or datareader) and at the same time, adding the "ALL" item.

just a thought :)
adam
 
im not sure about this, as i usually dont work with databound controls, but after binding the dataset, couldn't you just add an item called 'ALL' at the index of 0? and on the selectedindexchanged event if the selectedindex is 0, run the 'all' query (or whatever you want to do).
databound list controls normally cry if you manipulate their (in-control) item list; manipulating the underlying data is best..

or you could just not bind the combobox, but still chuck in the values you need (from the dataset or datareader) and at the same time, adding the "ALL" item.
true :)
 
databound list controls normally cry if you manipulate their (in-control) item list; manipulating the underlying data is best.

hm, ok then. i just had a bit of a brainwave, why not just before you bind the dataset to the control insert a row into the dataset at row 0, with a fake primary key, with a value of ALL.

and then on the selectedindex event, simply run the unfiltered results.

good luck :)
 
precisiamente..
;)

actually you can add that row any time you like, the Combo should update.

The other cool thing is, if you write the query correctly, you dont even need to cater for the extra thing you added in code..

SELECT * FROM person WHERE personID = :parameter or :parameter = 0

and if you set your parameter to 0.. i.e. the ALL item in your box has a value of 0...
then you dont even need a different query! cool!
 
Back
Top