StrataFrame Forum

Combo TopMostValue and Nulls

http://forum.strataframe.net/Topic20554.aspx

By Aaron Young - 11/5/2008

Hi,

I have a combobox with a lookup list bound to an int field. For the int field, my BO returns 0 as an alternate for null and my TopMostValue is set to 0. I have read several posts on here which suggests that if I select the TopMostItem then it should write Null back to the database and not 0. In my case, it writes 0 back to the database.

My database can accepts nulls so there is no problem on that score. Given the other posts, should I be seeing Null or 0 written to the database?

Thanks in advance,

Aaron

By Dustin Taylor - 11/5/2008

You should be seeing the 0, so it is working as designed. It will return whatever value you specify as the TopMostValue. Smile
By Aaron Young - 11/5/2008

Thanks for the reply Dustin. Is it possibly to specify a null value for TopMostValue instead of 0? I tried Null but it throws an error.

Thanks.

By Dustin Taylor - 11/5/2008

Heh, I was afraid you would ask that w00t.  In short, no, the topmostitem isn't really designed to work with Null values.

If you have that need, you'll need to populate the combo manually, creating your own datasource for the combobox with a null top most item. Smile 

By Greg McGuffey - 11/5/2008

I do this all the time (have a field that accepts NULL and is using a combo). First, you setup the BO to set/return an alternate value for NULL. Note there are four possibilities for handling NULLs at the BO level: don't allow them, use a nullable type, return an alternate value in the BO if the db has a NULL, and both return an alternate value if the db is NULL and set NULL in db if the BO contains the alternate value. You want that last one. Sounds like you may have done this and are using zero. A good choice if valid values are positive integers. Next, you setup you combo to have a top most value. The value itself is zero, as that actually means NULL. Setup the topmosttext to be either a space or some text indicating that no value is selected. When the user selects the top most value, the property in the BO gets a zero, which translates into a NULL when saved to the database. BigGrin
By Trent L. Taylor - 11/5/2008

Yup, Greg is on fire today BigGrin
By Aaron Young - 11/5/2008

Yeah, Greg is on fire Smile

I had the wrong setting in the BO - I was just returning an alternate value rather than setting it too.

Thanks Greg

By Greg McGuffey - 11/6/2008

Anytime. Glad you got it figured out! BigGrin
By Aaron Young - 11/6/2008

That's just it Greg, I didn't figure it out - you did! Smile