Bound Control

  • Thread starter Thread starter Jim Heavey
  • Start date Start date
J

Jim Heavey

With a DropDown box which is bound to a datasource, how do I do the
following:

1. Cause the first item in the drop down box to not show up as already
selected.
2. Provide an option which would indicate that no items in the dropdown
box are acceptable choices. Say for instance, I want a choice to be "Item
Does not Exist".

The only way that I can figure out how to do this would be to not bind it
to my datasource, but build the entries manually and make the first entry
the "Items Does Not Exist". Is this the best way to accomplish this task?

Thanks in advance for your assistance!!!!!!
 
After you do the binding, you can set the SelectedIndex to -1 which will
'unselect' any items. THere are a couple of ways to get your Item does not
exist thing to work. You could add a datarow to the table and this would be
an allowable value. However, if you are using a DataRelation this approach
will cause you some trouble (b/c unless you do some contortioins, you'll
have child records without parents). On the other hand, you could bind the
grid to a dataview for instance and adjust the rowfilter. However, if hte
dataview.count is 0 then you could rebind to another array/datatable etc and
have its only value be "Item does not exist" Simlilary you could build in a
dummy parent record = to some number you know you'll never use and then
build a child record with that as it's Column 0 for instance and column 1
co9uld be a description which = "Item does not exist" If no 'real' value is
selected, you could have the control select item 12102220 (dummy value) and
then the related child (12102220 - Item does not exist) will show.

In short, there are a few ways to address this... all in all though, if you
use bound data, and just add a datarow for this item, then it should show if
no real value is available to bind to.
I have an example if it would help (It's late and I can tell my writing
probably isnt' all that clear).
Let me know.

Cheers,

Bill
 
1. Cause the first item in the drop down box to not show up as already
selected.

Set the SelectedIndex propery to -1
2. Provide an option which would indicate that no items in the dropdown
box are acceptable choices. Say for instance, I want a choice to be "Item
Does not Exist".

Do you mean to have an entry to represent the null value. Or do you
want an entry in the list like "None of the above/below" that the user
can select, and this is the value you want to store in the database.
The only way that I can figure out how to do this would be to not bind it
to my datasource, but build the entries manually and make the first entry
the "Items Does Not Exist". Is this the best way to accomplish this task?

Thanks in advance for your assistance!!!!!!

One possibility would be to load the DataSet with the valid values,
say by running a select statement. Then before binding the combo box
add a record to the table (of the datsset) containing the value you
want to display for none of the above. Though the user will select
this, what value should be wtitten to the database when the user
selects this, should it be null or what?

Regards
Michael
 
Back
Top