StrataFrame Forum

Grid Refresh -Binding Error

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

By Ertan Deniz - 6/20/2008

I have list of services (Object) in my grid. I've added a record (Services Object) on different page. Then, refresh the grid when I came to Grid page. I have got the error below.

An error occurred while refreshing the data from field 'Services.unitset_id' to property 'SelectedValue' on control 'editUnitSet.'

When I open the page from menu. I have seen the added record.

By Trent L. Taylor - 6/23/2008

You haven't provided enough information for me to help you diagnose your problem.  Please post a stack trace and/or a quick sample that reproduces your problem.  Thanks.
By Ertan Deniz - 6/29/2008

Sorry. Last week was my holiday week.

I've tested my screen and I had no error for the above condition. It might be under specific conditions. If I find that case, I 'll inform you.  

By Ertan Deniz - 6/30/2008

I've encountered with same error.

In my form ; There is a grid which lists the objects (called Services).

and There are UI controls which shows the current object's properties. (Current object is selected on the grid.)

If Business Object has no records. (After a query) I've got the error below ;

"An error occurred while refreshing the data from field 'Services.unitset_id' to property 'SelectedValue' on control 'editUnitSet.'"

editUnitSet is a combobox and populated on formload from another Business Object. Since Business Object (Services Object) has no current record, and has no valid unitset_id as well. Binding mechanism goes on working.

I've searched from help and found the topic ;

What Happens to an Empty Business Object
StrataFrame automatically removes all control bindings when the business object has no records. 
The instant the business object is populated with data, the bindings are automatically re-created and the presentation layer controls are updated.

If so, why do I get the error ? What is wrong with my case ?

By Ertan Deniz - 6/30/2008

Stack Trace of the above error :

at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)

at System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)

at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)

at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)

at System.Reflection.RuntimePropertyInfo.SetValue(Object obj, Object value, BindingFlags invokeAttr, Binder binder, Object[] index, CultureInfo culture)

at System.Reflection.RuntimePropertyInfo.SetValue(Object obj, Object value, Object[] index)

at MicroFour.StrataFrame.Business.BusinessLayer.RemoveBinding(Control ControlToRefresh, String PropertyName)

at MicroFour.StrataFrame.Business.BusinessLayer.RefreshControl(IBusinessBindable ControlToRefresh, Boolean DataPresent)

By Ertan Deniz - 7/1/2008

The error was related the parameters given in Listpopulating Event. Null control  was missing. Now, when BusinessObject has no records, I'm not getting the error specified. I 've continued working on the form ;

I 've requeried the object (which is bound to the grid and UI controls which show current object) with parameters that returns records . Object had records after query. I've got the new error. (See details)

Type : System.InvalidCastException, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
Message : Specified cast is not valid.
Source : Medin.Business.Materials.New
HelpLink :
TargetSite : Void SetValue(System.Object, System.Object)
StackTrace :
 Medin.Business.Materials.Purchase.Services.Field_unitset_id_Descriptor.SetValue(Object component, Object Value)
  C:\Documents and Settings\ertan.deniz.KULLANICI\My Documents\Visual Studio 2005\Projects\Medin.Materials\Medin.Materials.Purchase.Business\Purchase\Objects\Services.Designer.cs:line 1235
 System.Windows.Forms.BindToObject.SetValue(Object value)
 System.Windows.Forms.Binding.PullData(Boolean reformat, Boolean force)
 System.Windows.Forms.Binding.UpdateIsBinding()
 System.Windows.Forms.Binding.CheckBinding()
 System.Windows.Forms.Binding.SetListManager(BindingManagerBase bindingManagerBase)
 System.Windows.Forms.ListManagerBindingsCollection.AddCore(Binding dataBinding)
 System.Windows.Forms.BindingsCollection.Add(Binding binding)
 System.Windows.Forms.BindingContext.UpdateBinding(BindingContext newBindingContext, Binding binding)
 System.Windows.Forms.Binding.SetBindableComponent(IBindableComponent value)
 System.Windows.Forms.ControlBindingsCollection.AddCore(Binding dataBinding)
 System.Windows.Forms.ControlBindingsCollection.Add(Binding binding)
 MicroFour.StrataFrame.Business.BusinessLayer.AddBinding(Control ControlToRefresh, String PropertyName, String FieldName)
 MicroFour.StrataFrame.Business.BusinessLayer.RefreshControl(IBusinessBindable ControlToRefresh, Boolean DataPresent)

By Trent L. Taylor - 7/1/2008

Well, there seems to be quite a bit going on, but the last error seems to be the easiest to dianose.  It is a cast exception so that value that is being passing into the Set of the unitset_id field is not a type that can be converted into the type it is expecting.  For example, this may be a integer field and character data is being passed into the Set of the property.
By Ertan Deniz - 7/1/2008

I've attached the code clock below. I'm trying to fill the object. (FillDataTable) At this time,
SetValue is running and I'm gettinng the error. (It is signed with red on the code block.)
It is interesting that left side of the assignment has a value (valid unitsetid) but right side has null value.
So, casting error. The object has values coming from DB. But there is an assignment (SetValue) which is trying
to assign values on the object which is filled. Normally, After object has values coming from DB, binding mechanism will start.
Why does SetValue run at this time ? What is the meaning of SetValue ?

Is the order of assignment true ? I expect that right side must be left side ? Because, I'm displaying values from DB.

Do you explain the process briefly ? Fill, Bind etc.

private class Field_unitset_id_Descriptor : MicroFour.StrataFrame.Business.FieldPropertyDescriptor
        {
            public Field_unitset_id_Descriptor() : base("unitset_id") { }
            private System.Type _PropertyType = typeof(System.Int32);
            public override object GetValue(Object component)
            {
                return ((Services)component).unitset_id;
            }
            public override void SetValue(Object component, object Value)
            {
                ((Services)component).unitset_id = (Nullable<System.Int32>WinkValue; (Error : Specified Cast is not valid.)
            }
            public override System.Type PropertyType
            {
                get
                {
                    return this._PropertyType;
                }
            }
            public override System.Type ComponentType
            {
                get
                {
                    return _ComponentType;
                }
            }
        }

By Ertan Deniz - 7/1/2008

As a described above, I fill the object and get a list of records in the grid and current record on the form view. (UI controls) I couldn't get the error. Values are coming from DB and displayed on the form. (I don't have the error)

But, Requery object and no records. This is also working.

Requery object but there are records at this time. I 've got the error.

By Ertan Deniz - 7/3/2008

Any Comment ?
By Trent L. Taylor - 7/6/2008

I have not had a change to look at this in depth.  I tried to re-produce the problem quickly, but had no issues.  Since I am going to have to take your code and try and reconstruct your issue, I have not had a chance to do this.  If you want to supply the sample, it may go faster.  But as of yet, I have not been able to reproduce nor have I spent an extended amount of time trying to reproduce since I couldn't reproduce it quickly.

So at present, this is on a list to look at, and it is something that we will try to look at prior to the final 1.6.6 build.  If you want to provide a sample showing the error versus just showing a code snippet, it will definitely speed up the process.

By Ertan Deniz - 7/7/2008

I think there is conflict or complication. What do you say the conflict with the message and code ?

The line from my code shows that unitset_id gets value.

((Services)component).unitset_id = (Nullable<System.Int32>Value; (Error : Specified Cast is not valid.)

But message says  control gets value ;

"An error occurred while refreshing the data from field 'Services.unitset_id' to property 'SelectedValue' on control 'editUnitSet.'"

 


By Trent L. Taylor - 7/8/2008

Ertan,

I don't see anything past an invalid cast exception.  Why can't you just return an alternate value on Null so that a valid value is returned to the grid?  I do not believe this to be a BBS or BO "bug" or "issue" but rather how it is designed.  If the control to which you are binding doesn't support a null value being returned, then you would want to ensure that it can be cast by supplying a valid value.  Just from looking at your code snippet and stack trace, this is what I would recommend.

By Ertan Deniz - 7/8/2008

I've developed a test a project. And seen that no problem at that case.

Original point in my project also have been tested and also no problem.

The problem may be related development environment (DLL versions etc).

By Trent L. Taylor - 7/9/2008

OK...that makes more sense.