changing an ID and Name at the same time, how do people handle?

changing an ID and Name at the same time, how do people handle?

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


mtagliaf posted on Monday, July 16, 2007

Say I've got an Order object that contains properties for CustomerID and Customer name.  In the UI, I want to pop up a "picker" dialog so the user can pick a customer, and then set the custID and name at the same time on the order object.  I usually like to do this with a "Set" procedure on the Order object:

sub SetCustomer(uID as guid, cName as string)
  if not fCustID.equals(uID)
   
fCustID = uID
    fCustName = cName
    PropertyHasChanged("CustName")
  end if
end sub

I like to do it this way so the UI coder can't accidentally set one without the other. 

It seems, though, that when I bind a Textbox to CustName on the form, it's not refreshing properly when the name is changed.  The data in the Order object looks ok, it's just not making it to the form.  I don't have to do the "IsDirty checkbox" hack anymore, do I?

matt tag

RockfordLhotka replied on Monday, July 16, 2007

You need to call PropertyHasChanged for both properties.

Or, don't call PropertyHasChanged at all, but rather

ValidationRules.CheckRules("id")
ValidationRules.CheckRules("name")
MarkDirty()

In other words, run the rules for both changed properties and then mark the object as dirty.

 

Copyright (c) Marimer LLC