DataGridView.OnPaint() and the BusinessBase.IsValid Property

DataGridView.OnPaint() and the BusinessBase.IsValid Property

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


mfegter posted on Monday, April 27, 2009

I am developing a Windows Form application using the CSLA 2.0 framework.  I was stepping through my code, and everytime a DataGridView is shown on the form through its OnPaint() event (specifically System.Windows.Forms.DataGridView.OnPaint(PaintEventArgs e)), the IsValid property of my BusinessBase object is checked. 

No where in my form code have I called the .IsValid property (yet -- I'm just trying to get the form to display values right now, no inserts/updates/deletions have been implimented).  I have all the form objects (the form itself, a group control, the datagridview itself) to have their CausesValidation properties set to false.

This seems to be quite inefficient, since I noticed the IsValid property being checked 8 times for each record in the DataGridView control.  I have 8 controls on my form (labels, drop down lists, etc.)

Any ideas?

RockfordLhotka replied on Monday, April 27, 2009

IsValid is probably being invoked through IDataErrorInfo, which is part of the data binding infrastructure.

Windows Forms data binding is terribly inefficient. You have just found the tip of the iceberg.

For the most part it doesn't matter (fortunately), because this is all running on a client workstation, so you have near-supercomputer power and can afford to waste some cycles.

However, this has certainly impacted the design of CSLA. This is why, for example, the validation and authorization subsystems minimize invocation of actual business rules, and try to cache the results when possible. This is why the broken rules collection exists, and the rules aren't checked each time the UI asks if the object is valid.

In other words, data binding is inefficient. But if you know how it is inefficient, then it isn't as big a deal as it might otherwise appear.

Remember that premature optimization is an anti-pattern.

Copyright (c) Marimer LLC