DataBinding in Win UI

DataBinding in Win UI

Old forum URL: forums.lhotka.net/forums/t/333.aspx


Pradeep posted on Friday, June 09, 2006

The BindField method for binding a control to a property works pretty good. As soon as I update the control, my business object is updated automatically.
 
But one thing I noticed is that, inorder for .Net to update the business object, I have to tab out of that control or click on another control that is databound (basically change focus to another control). This is bit frustrating. Because, it does not happen if I just click some where outside of the control (on the form). I must click on another bound control.
 
Is this a known issue or am I missing something? Is there any work around for this? I dont want to write a bunch of lost focus methods on each of my control, because that would defeate the purpose of DataBinding.
 
I am using Infragistics control. I hope it has nothing to with infragistics control and is directly related to the way .Net does data binding. Also I am using .Net 1.1 and not 2.0
 
Please let me know your thoughts and suggestions regarding this issue.
 
Thank You
 
 

RockfordLhotka replied on Friday, June 09, 2006

The way data binding works is such that you do have to exit the control for the value to be set into your data source (in this case your business object). You can call EndEdit on the binding source to force data binding to put the last value into the data source. Also, there's a property you can set on each control so the binding source will do the updates on keystrokes (changed events). I think this only works when using the binding source approach from .NET 2.0 though...

vbexpert replied on Sunday, June 11, 2006

RockfordLhotka:

there's a property you can set on each control so the binding source will do the updates on keystrokes...

May I know what the property name is? I couldn't figure.

RockfordLhotka replied on Monday, June 12, 2006

It is the Data Source Update Mode in the Advanced dialog under the Databindings property of a control.
 
Rocky


From: vbexpert [mailto:cslanet@lhotka.net]
Sent: Sunday, June 11, 2006 7:50 PM
To: rocky@lhotka.net
Subject: Re: [CSLA .NET] DataBinding in Win UI

RockfordLhotka:

there's a property you can set on each control so the binding source will do the updates on keystrokes...

May I know what the property name is? I couldn't figure.




Brian Tian replied on Thursday, June 29, 2006

 

I have the same problem,  but I use .Net 2.0,  Infragistics 6.2 and CSLA 2.0

Thank you, I know how to do it now.

Brain

Cslah replied on Friday, June 30, 2006

We've found that sometimes you want to have the data update on keystrokes, such as a numeric field used in calculating a result while still having the formatting applied (if needed) on lost focus of the control. Fortunately, you can still use databindings for this. The BO will get updated OnPropertyChanged, but the formatting won't apply until the control loses focus. It works great. This is what we use for a nullable decimal formatted as currency.

Dim db As System.Windows.Forms.Binding
db = control.DataBindings.Add(propertyName, dataSource, _
dataMember, True, DataSourceUpdateMode.OnPropertyChanged, "", "c")
db.DataSourceNullValue = Nothing

phucphlq replied on Friday, September 22, 2006

But it don't work in grid and treelist control. In grid, we only assign Grid.DataSource = List.

How to do?

Copyright (c) Marimer LLC