Solved

Null values in bound combobox

Posted on 2006-06-13
7
344 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
Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 
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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

809 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