StrataFrame Forum

Broken rule not shown when navigating in DexExpress.XtraGrid

http://forum.strataframe.net/Topic8118.aspx

By Chan - 4/15/2007

Hi,

I have business rule checking in CheckRulesOnCurrentRow(). When I edit and navigate to row in DevExpress.XtraGrid, error provider doesn't show error sign even there are broken rules. I have set CheckCurrentRowBeforeNavigate to True.

However, It does show error if I bind field to textbox or save record.

Any ideas?

Thank you

By Trent L. Taylor - 4/16/2007

I recommend that you look at the BusinessBindingSource sample that comes with the framework.  If shows how to bind a BO to a grid using a BusinessBindingSOurce while respecting the broken rules and displaying a error provider.
By Chan - 4/16/2007

Hi,

I have tested BusinessBindingSource sample. However, it doesn't show error provider for required field when navigating row. HOwever, it works for saving record.

By Trent L. Taylor - 4/16/2007

Unless you call the CheckRulesOnCurrentRow method the event will not be raised with using a grid when navigating alone.  This is due to the nature of each grid and canceling a row navigation.  You can mange this yourself by calling the CheckRuleOnCurrentRow event in the Navigating event of the BO.  You will then have to cancel navigation yourself on the grid depending upon which grid you are using.
By Chan - 4/16/2007

Hi

Thank you for reply. Doesn't grid respect BO.CheckCurrentRowBeforeNavigate ?

By StrataFrame Team - 4/17/2007

The grids do not always respect the CheckCurrentRowBeforeNavigate.  The reason being that they don't use the same mechanism for the record pointer that the business object does.  The grids use the ICurrencyManagerProvider.CurrencyManager.Position property for their record pointer.  When the position within the grid is set, it fires the Navigated event on the business object, which checks the business rules.  However, if the rules fail, the BO cancels navigation and attempts to set the CurrencyManager.Position back to the previous record, however, since this is happening within the PositionChanged event of the CurrencyManager, the CurrencyManager will not respect the request to change the position within the PositionChanged event handler.

So, you're best bet would be to just turn off the CheckCurrentRowBeforeNavigate property and add a handler to the BO's Navigated or Navigating event and manually call CheckRulesOnRow().  It won't prevent the grid from leaving the record, but it will keep the Position and the CurrentRowIndex in sync.