Solved

Null values in bound combobox

Posted on 2006-06-13
7
345 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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB.NET Repostiory Pattern 7 48
SqlServer no dupes 25 37
"Emulate" TAB key when press Enter Key 3 44
Vb.net threads keep increasing 2 35
Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

790 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