Solved

Null values in bound combobox

Posted on 2006-06-13
7
341 Views
Last Modified: 2008-03-10
I use a combobox to edit the field "ReutersChains" in the table "Instruments".
This is a numeric field, the corresponding strings are stored in the table "ReutersChains".

Simple binding to instruments.ReutersChains. (uses selectedValue)
Complex binding to ReutersChains.Id and name.

This works perfectly.

Now what would be a good (the best?) way to enable clearing the field?

Option1:
Add a NONE record with id 0 to the table ReutersChains.

Option2:
If I clear the text of the combo, somehow I place null or 0 in the field ReutersChains.
This would involve some figuring out how to program this.
As far as I know the binding to selectedValue doesn't support such a thing, right?

Other ideas?
0
Comment
Question by:NicoLaan
  • 3
  • 3
7 Comments
 
LVL 9

Accepted Solution

by:
lojk earned 250 total points
ID: 16898107
ACtually the convention is to add (none)
including the brackets, to ensure is top of the list. This approach has some major bonuses later when you come to join the two tables because you dont need to add specific casting and formatting for null values when outputting. Of course once you adopt this standard it makes sense to apply it for all similar lookup table combos..

in an unbound (dropdownlist ) combo you can normally set the selected index to -1, which would clear the combo selection but according to the msdn you cant do this on a databound.. Is there no way you can just use an unbound combo and handle the loading and evaluating as required?
0
 
LVL 4

Author Comment

by:NicoLaan
ID: 16900933
You're right about that, using the (none) value would be the most common method I think.
The problem is software using the current data would have to be changed. Now it will find a (none) (null) link with the reauterschains table. However changing this code would be easy and make it work more properly I feel.

If I'd use option 2 and do some clearing of the combo, doing it unbound would be an idea but really seems more messy.
0
 
LVL 9

Expert Comment

by:lojk
ID: 16900972
update reuterschain set ID=0 where id=null... odds are youll probably end up removing code rather than adding it to implement this change in the app.

Nulls are often more trouble than they are worth.. if you can include a known 'null' value (i.e. zero) it is always simpler when creating reports, loading combos et.al

Of course the question is did you not consider these problems during your design phase? (*Excessively Loud Coughing and mumbling*) Perhaps next time, eh?

;-)
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 4

Author Comment

by:NicoLaan
ID: 16906959
My boss designed the start of it, I'm just cleaning up his mess. ;-)
Well, honestly he did a good job most of the time but consistency slip ups like these I do occasionally find and then we discuss, redesign this part or that part.
Also caused because it's a big work in progress, new insights partially changing database and software design.
I think I would have designed it the proper way with (none), so I could have made some other slip ups.
0
 
LVL 9

Expert Comment

by:lojk
ID: 16907024
Theres always *one more* slip up to make...

0
 
LVL 4

Author Comment

by:NicoLaan
ID: 17075359
Ouch, sorry, I completely forgot to rate it.
Sorry about that, thanks lojk for your thinking and TheLearnedOne for your reminder.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Delivering innovative fully-managed cloud services for mission-critical applications requires expertise in multiple areas plus vision and commitment. Meet a few of the people behind the quality services of Concerto.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

939 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now