validating textbox problems

validating textbox problems

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


gmclean posted on Thursday, May 25, 2006

Hello,

I have what I hope is a simple problem but I can not seem to get it figured out.

I have a windows form bound to a business object. When I change data in a field then hit TAB or click out nothing happens unitl I TAB or click again. I created a validating event handler to see what was happening and the first time through the validating event fires but the SET of the property tied to the control does not fire. When I TAB the second time, validating fires, property SET fires and all proceeds as expected. This happens on all the controls in the form.

I checked the value of e.Cancel in the validating event handler and it was false. I also created some controls that were not bound to the business object and they did not require two TABs to move out. This makes think the business object is the problem but since I never get to the SET of the property until the second TAB, I am not sure what is happening.

Any suggestion?

Thanks

George

phowatt replied on Thursday, May 25, 2006

I usually suspect some event handler somewhere.  We override the ProcessCmdKey method in our forms much to our disadvantage and often times we find our culprit there.  On occasion it can be corruption.  But when all else fails I start building a test form and try to add one control at a time from the bad form to isolate where the problem starts.  I doubt that it is the business object but if you have a form with just one control bound to the business object property and nothing else is going on in your form and you still have the problem then it might be the business object.

ajj3085 replied on Thursday, May 25, 2006

It sounds to me like there is an exception occurring somewhere in the property setting for the BO. 

For some reason, data binding swallows all exceptions and then seems to 'shut down'  I've noticed this behavior in .Net 1.1, but not in .Net 2.0 (yet).

I'm not sure a good way to handle this; I ended up not using the databinding in .Net 1.1 because it was quicker listen for the Textchanged event and manually stick the data into the object.

Andy

gmclean replied on Wednesday, May 31, 2006

I found my problem by disecting the form and BO as suggested.

I was not declaring my private child objects correctly in the BO.

I was declaring like this:
Private mUnits As UnitCollection

instead of this:
Private mUnits As UnitCollection = UnitCollection.NewUnits()

I guess some sort of exception was firing but I never saw it as you suggested.

I suppose I should pay closer attention to the examples in the CSLA book!

Thanks for the suggestions

George

fzamora replied on Wednesday, July 12, 2006

I have been battling with the same problem for a few days now.  It appears that the event will cause this problem only when I try to access the rules for the property for my business object in the event.  Whenever I perform some other logic in my Validated event, it does not happen.  I was initially handling the validating event so that I could stop navigation but I started using validated instead because I thought validating was causing the problem.  If anyone solves this issue can you please post the fix.

 

private void txtFName_Validated(object sender, System.EventArgs e){

 

MAT.CSLA.BrokenRules.RulesCollection rules = _Employee.BrokenRulesCollection.RulesForProperty("FirstName");

...

}

Copyright (c) Marimer LLC