Solved

Null values in bound combobox

Posted on 2006-06-13
7
334 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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

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 …
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

708 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

14 Experts available now in Live!

Get 1:1 Help Now