Print Page | Close Window

DynamicEntity with expression defined on underlying DataColumn

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce Classic
Forum Discription: For .NET 2.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=379
Printed Date: 23-May-2025 at 7:59pm


Topic: DynamicEntity with expression defined on underlying DataColumn
Posted By: labcede
Subject: DynamicEntity with expression defined on underlying DataColumn
Date Posted: 21-Aug-2007 at 2:03pm
When creating my DataTable for the EntityTypeInfo, I have included a DataColumn that has an expression defined (basically the summary of the row values.

This dynamic entity list is bound to a .NET grid using the DataGridViewBindingManager.  I've added ViewDescriptors to the DataGridViewBindingManager (at run-time) so that I can display the data in the associated DataGridView.

After modifying a cell value, I would expect the Total column to be automatically updated.  However, this is not the case.  Only when the cell is in focus (selected by the mouse or 'tabbed into') does the value update.  How do I work around this?



Replies:
Posted By: kimj
Date Posted: 22-Aug-2007 at 8:58am
I'm not really sure when the DataColumn expression is evaluated, so there may be other ways to accomplish this, but here's one way.
 
First, be sure to use an EntityList as the data source for the grid and binding manager. 
 
Next, you need to fire a PropertyChanged event for the expression property.  (Since the DynamicEntity derives from Entity, PropertyChanged will automatically be fired for "simple" properties already.)  If you've used something similar to the sample DelegateHolder class in the tutorials, you can take a somewhat inelegant approach and add logic to the Setter method to do this:
 
public void Setter(object pParent, object pValue) {
   DataRow aRow = (DataRow)pParent;
   aRow[mColumnName] = pValue;
 
   // If Qty or Cost changes, then fire event for calculated Total
   if (mColumnName == "Qty" || mColumnName == "Cost" {
      DynamicEntity ent = pParent as DynamicEntity;
      ent.ForcePropertyChanged(new PropertyChangedEventArgs("Total"));
   }
}
 
Since the sample DelegateHolder is meant to be multi-purpose you'll probably want to do some refactoring to come up with a cleaner design than this.
 


Posted By: labcede
Date Posted: 22-Aug-2007 at 9:44am
thanks!



Print Page | Close Window