New Posts New Posts RSS Feed: DynamicEntity with expression defined on underlying DataColumn
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

DynamicEntity with expression defined on underlying DataColumn

 Post Reply Post Reply
Author
labcede View Drop Down
Newbie
Newbie


Joined: 25-Jul-2007
Posts: 8
Post Options Post Options   Quote labcede Quote  Post ReplyReply Direct Link To This Post Topic: DynamicEntity with expression defined on underlying DataColumn
    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?
Back to Top
kimj View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 1391
Post Options Post Options   Quote kimj Quote  Post ReplyReply Direct Link To This Post 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.
 
Back to Top
labcede View Drop Down
Newbie
Newbie


Joined: 25-Jul-2007
Posts: 8
Post Options Post Options   Quote labcede Quote  Post ReplyReply Direct Link To This Post Posted: 22-Aug-2007 at 9:44am
thanks!
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down