WinForms/LLBLGenPro databinding issue

Posts   
 
    
adamw4
User
Posts: 6
Joined: 04-Feb-2009
# Posted on: 09-Jun-2009 08:16:45   

Hi

I've taken over the maintenance of an application and have noticed the following issue which I am not sure is desired behaviour of databound WinForms controls.

The application uses LLBLGen Pro 2.5, Krypton Toolkit (for GUI controls) in a C# WinForms application (framework 2.0).

When the user clicks on a textbox for manual date entry (not a picker) or a combo box, and then tries to click or tab away, focus jumps back to the control originally clicked on. I believe this might be occurring because the value in the field is being validated upon focus being lost and is not valid for the bound field on the entity. An empty string in the textbox should be valid for a date field I would have thought (null - the underlying column is nullable). Same thing happens with the dropdowns regardless of whether the underlying column is nullable or not.

I would like to present errors upon the user clicking the save button, through the ErrorProvider mechanism as its unintuitive behaviour that once you enter a control you can't leave it until a valid value is entered/chosen.

Is this a peculiarity of the way this has been implemented or is this normal behaviour?

The databindings are being added as follows:

        this.txtDateIssued.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.bindingSourceCheck, "DateIssued", true));

DateIssued is a nullable DateTime column in the database.

Regards Adam

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 09-Jun-2009 08:34:16   

This was reported and discussed before, but the thread wasa HelpDesk(private) thread. So I'll just copy the important replies from the support team.

Walaa wrote:

As far as I know this is a Windows Forms Databinding issue.

When the user Tabs off the TextBox, validation occurs and the data binding engine (Binding type) will attempt and update the data source property with the bound Control value (TextBox.Text). If an exception occurs, validation will fail and the focus will not leave the bound Control. To allow focus to leave, you can add a BindingComplete event handler and set e.Cancel to false

ref: why-can-t-i-tab-out-of-my-control-when-using-data-binding

Otis wrote:

When you enter a value and then backspace till the control is empty and then press tab for example, nothing is sent to the entity. Place a breakpoint in the property setter of the bound entity property and it will never hit AFTER you press tab to move away from the textbox.

That alone proves it's a databinding problem. The thing is, if you switch off formatting, (so pass false to enable formatting in the textbox binding add), it works but the value isn't stored either due to another fantastic screw up of the winforms team.

It's as if it can't deal with nullable<int> types, and that's no surprise as there are more areas where the winforms code falls flat on its face due to the presence of nullable<T>

I tried various things, but I can't find out how to trick it into either passing null to the entity property. So it's not something in our code, as our code is never called: when pressing TAB to get out of the textbox, no value is sent to the entity, so no code inside the entity is ran nor is it validated there.

adamw4
User
Posts: 6
Joined: 04-Feb-2009
# Posted on: 10-Jun-2009 02:40:47   

Thank you very much.

I was able to allow the user to move away from a field without a valid value, by implementing the BindingComplete event handler.

However, when a valid value is entered in one of the bound fields (i.e. it can be successfully validated), all other fields bound to the same datasource revert to their original value.

Is there something else I need to do?

adamw4
User
Posts: 6
Joined: 04-Feb-2009
# Posted on: 10-Jun-2009 03:16:18   

On further inspection, it appears to be related to the second part of your response. Empty fields and the "blank" selection in a dropdown (which has a selectedvalue of null) are failing validation and are instead reverting to their previous values upon the successful validation of another field.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 10-Jun-2009 04:56:42   

Related to this: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=12166

This is issued in the Winforms Validation example at http://llblgen.com/pages/examples.aspx

David Elizondo | LLBLGen Support Team
adamw4
User
Posts: 6
Joined: 04-Feb-2009
# Posted on: 11-Jun-2009 04:19:29   

Thank you.. have worked around the issues now with your assistance.

What can I say.. WinForms databinding.. a potential time saver that only causes pain and slows development simple_smile

Adam