Support for System.DBNull in bo.SetValue method


Author
Message
Edhy Rijo
E
StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Hi Ben,

Thanks for the fast response.  I forgot to mention, that this is a DevExpress control "DevExpress.XtraEditors.SearchLookUpEdit" which I included in the SF Inherited UI library.

I posted the class in this thread http://forum.strataframe.net/FindPost30273.aspx I would appreciate if you can provide any vb code to get this done.

Edhy Rijo

StrataFrame Team
S
StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
Yes, there are ways to prevent this.  The System.Windows.Forms.Binding class has a DataSourceNullValue property on it that allows you to specify the null value to put back into the data source when the control is null; it defaults to DBNull.Value.  So, you need to change this value for your binding in order for it to send back Nothing (or null, if you prefer) instead of DBNull.Value.

The bindings are created by SF through the BusinessLayer's AddBinding() method.  It's private, so you would need to change the source code and recompile if you want to change it there.  Simply add the line loBinding.DataSourceNullValue = Nothing where it's initializing the binding.

To avoid changing the source code, you would need to add a handler to your control's DataBindings.CollectionChanged event (the event is actually on the collection returned from the DataBindings property).  When that event fires, you can detect a new Binding and set its DataSourceNullValue to Nothing.  The BusinessLayer will push and pop data bindings from time to time, so you'll need to handle that event to configure each one properly; you can't do it just once.  You can also create a static method somewhere and add it as the handler to the controls as needed so you can program the logic in one place.
Edhy Rijo
E
StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Hi Trent, Ben,
I am using more and more DevExpress controls and sometimes when hitting a DBNull value, the Business Object is not able to handle it, even though I have set the "NULL Value Option" in the BOM to "Return Alternante on Null = 0", but the SetValue(ByVal component As Object, ByVal value As Object) of the BO does not take System.DBNull into consideration.

For example, this line below, will throw an exception if the value is System.DBNull
 DirectCast(component, bizTransaction).FK_Vendor_Carrier = CType(value, System.Int32)

But if I change the bo.Designer to something like this, it will work just fine, but the bo.Designer will be overwritten next time I use the BOM.

 Case bizTransactionFieldNames.FK_Vendor_Carrier
                    If value Is Nothing OrElse IsDBNull(value) Then
                        DirectCast(component, bizTransaction).FK_Vendor_Carrier = 0
                    Else
                        DirectCast(component, bizTransaction).FK_Vendor_Carrier = CType(value, System.Int32)
                    End If


Is there a way to overcome this situation?


Edhy Rijo

GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search