ORMEntityValidationException not catched when calling bindingsource.endedit()

Posts   
 
    
JoeyM
User
Posts: 15
Joined: 07-Aug-2012
# Posted on: 03-Nov-2012 16:18:51   

Hello,

Im using VS2010 ult. LLBLgen V3.5

At the moment im working on a test project to get my validation layer right (before i build it into my application). Im using injection validation, and override the fieldvalidate classes etc.

My test project has two entities -> very basic, some fields allow null, some not etc.

I created a new Win Forms, added one of my entities as a "DataSource" en created a detail screen of my entity, resulted in a bindingsource with a binding navigator.

In the validation class, i created a validation rule in the "OnValidateFieldValue" that checks if the name of the entity has a length of 4.

On my form a created a save button, and in the "On_Click" method, the following code is created:

try { InboundInterfaceEntity i = (InboundInterfaceEntity)inboundInterfaceEntityBindingSource.Current; inboundInterfaceEntityBindingSource.EndEdit();

            using (DataAccessAdapter adapter = new DataAccessAdapter())
            {
                adapter.SaveEntity(i, true);
            }

        }
        catch (ORMEntityValidationException v)
        {
            frmValidationResults a = new frmValidationResults();
            a.ValidationMessages = v.Message;
            a.ShowDialog();
            errorProvider1.UpdateBinding();
            return;
        }
        catch (Exception ex)
        {
            throw;
        }

Allright, so i run the form, details of the first entity are shown in the form and i change then name of the entity to five characters, i don't leave the textbox (that would directly cause the "onvalidatefieldvalue" but i hit the SAVE button.

In the On_Click method (see above) i call the Bindingsource.EndEdit() function. This function cause an ORMValidationException in the "OnValidateFieldValue" override -> but in the above code the Exception is not Catched, even if i add a "Exception" catch, it doesn't get in that.

How can i catch the message (so i can properly stop the save routine etc).

Just to be sure, this only is the problem when the cursor is still in the textbox and i hit the save button.

Regards, Joey

JoeyM
User
Posts: 15
Joined: 07-Aug-2012
# Posted on: 03-Nov-2012 18:47:30   

----- Update 2.

I just found out that i get different behaviour when i use a button instead of the toolstrip button on the form. It appears that buttons on the toolstrip don't cause a focus switch and there for the "validation" is not thrown before it enters the button_click event. (that's my guess now). Still it is strange that when i call the EndEdit the ORMValidationMessage is not catchable...

When i add a normal button to the form, then it first goes to the validatefieldvalue before the button_click event is thrown. (switch of focus = causing onvalidatefieldvalue?).

Any body has a clue why this behaviour is different??

Regards, Joey

JoeyM
User
Posts: 15
Joined: 07-Aug-2012
# Posted on: 03-Nov-2012 19:07:18   

Update 3 ----

Found somebody with the same problems: http://www.experts-exchange.com/Programming/Languages/.NET/Visual_Basic.NET/Q_24465239.html

The funny thing is, his solution -> changing the focus in the toolstrip button _ click event is easy done, and it causes the OnValidateFieldValue but.... still not able to catch the ORMValidationException rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr

Regards, Joey

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 05-Nov-2012 05:21:57   

You are catching the exception on the click event of the save button, but I think the exception is raised before that, when the textbox looses the focus. If you set an error on the field at OnValidateFieldValue and use a validator control for the bindingSource I think you should be able to see the error at the GUI controls.

David Elizondo | LLBLGen Support Team