Data Binding Problem

G

Guest

Hi

I have defined my business object OrderItem as shown in the sample code fragment below

public class OrderItem
public event EventHandler UnitPriceChanged
private decimal m_unitPrice = 0.0m
..
public decimal UnitPrice
get { return m_unitPrice;
set
m_unitPrice = value
if (UnitPriceChanged != null) UnitPriceChanged(this, new EventArgs())




I use data binding to bind a TextBox's Text property to the OrderItem's UnitPrice property as follows in my OrderForm

txtUnitPrice.DataBindings.Add("Text", m_orderItem, "UnitPrice")

In some circumstances, when I type in a value in the TextBox and press Tab (or click on another control), the focus does not move to another control but retain in the same TextBox, forever. When this happens, I can't move to other controls anymore except closing down the OrderForm using the "X" button

Later, when I open up another model form - OrderItemDetailForm - and passing it the m_orderItem object for editing. The OrderItemDetailForm performs the same binding to UnitPrice property and everything seems like going fine. When the OrderItemDetailForm's closed and returned its parent, and I attempt to edit the Unit Price thru the txtUnitPrice control, the control locks my form again

May I know what is happening here? Or I have done something that does not conform to Windows Forms data binding practices

Thanks
-Y
 
N

Neil Allen

Hi,

I have defined my business object OrderItem as shown in the sample code fragment below:

public class OrderItem {
public event EventHandler UnitPriceChanged;
private decimal m_unitPrice = 0.0m;
...
public decimal UnitPrice {
get { return m_unitPrice; }
set {
m_unitPrice = value;
if (UnitPriceChanged != null) UnitPriceChanged(this, new EventArgs());
}
}
}

I use data binding to bind a TextBox's Text property to the OrderItem's UnitPrice property as follows in my OrderForm:

txtUnitPrice.DataBindings.Add("Text", m_orderItem, "UnitPrice");

In some circumstances, when I type in a value in the TextBox and press Tab (or click on another control), the focus does not move to another control but retain in the same TextBox, forever. When this happens, I can't move to other controls anymore except closing down the OrderForm using the "X" button.

Later, when I open up another model form - OrderItemDetailForm - and passing it the m_orderItem object for editing. The OrderItemDetailForm performs the same binding to UnitPrice property and everything seems like going fine. When the OrderItemDetailForm's closed and returned its parent, and I attempt to edit the Unit Price thru the txtUnitPrice control, the control locks my form again.

May I know what is happening here? Or I have done something that does not conform to Windows Forms data binding practices?

Thanks.
-YK


Dear YK

I've used this technique without any problems (Framework 1.1) .

Where you say "In some circumstances" can you describe the
circumstances?

Could you / are you prepared to supply a simple cut down version of
the program that exhibits the problem?

Regards

Neil Allen
 
M

Martin Robins

This behaviour is normally caused by an exception being thrown in the set
function for the property. Unfortuntely, M$ (in their infinite wisdom)
neglexted to include any facility within the databinding that allows the
developer to be made aware of any exceptions or handle them; instead it
simply stays in the control until it can pass the bound value to the
property without problem.

Personally, I ended up writing my own binding classes!

Martin


YK said:
Hi,

I have defined my business object OrderItem as shown in the sample code fragment below:

public class OrderItem {
public event EventHandler UnitPriceChanged;
private decimal m_unitPrice = 0.0m;
...
public decimal UnitPrice {
get { return m_unitPrice; }
set {
m_unitPrice = value;
if (UnitPriceChanged != null) UnitPriceChanged(this, new EventArgs());
}
}
}

I use data binding to bind a TextBox's Text property to the OrderItem's
UnitPrice property as follows in my OrderForm:
txtUnitPrice.DataBindings.Add("Text", m_orderItem, "UnitPrice");

In some circumstances, when I type in a value in the TextBox and press Tab
(or click on another control), the focus does not move to another control
but retain in the same TextBox, forever. When this happens, I can't move to
other controls anymore except closing down the OrderForm using the "X"
button.
Later, when I open up another model form - OrderItemDetailForm - and
passing it the m_orderItem object for editing. The OrderItemDetailForm
performs the same binding to UnitPrice property and everything seems like
going fine. When the OrderItemDetailForm's closed and returned its parent,
and I attempt to edit the Unit Price thru the txtUnitPrice control, the
control locks my form again.
May I know what is happening here? Or I have done something that does not
conform to Windows Forms data binding practices?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top