Accepted answer

i had a similar issue. i was binding to a treeview and needed to call refresh in response to the user canceling an edit operation. the refresh() method obediently puts all the original values back, but this was not reflected in my treeview ui. after consulting with the almighty google, i came across this solution:


this seems to force my treeview to update everything. the only drawback (and it's a pretty major one) is that it seems to collapse all the tree nodes, which causes the user to lose their place. i could just as well set my itemssource to null and back again...same effect, although this method would be simpler if you had a bunch of bound text boxes or something, since you wouldn't need to rebind every single one.

is there a better solution than this?

edited: yes there is...

a smarter-than-me coworker of mine came up with this solution, which seems to do the trick. in your partial class for the linq2sql object, add the following code:

public void sendpropertieschanged()
     foreach (system.reflection.propertyinfo prop in this.gettype().getproperties())

the you can just call this in your application code:

context.refresh(refreshmode.overwritecurrentvalues, employee);

all ui elements get the message, and update themselves appropriately. this even works for treeview controls and things like that where you don't want the ui to appear to "reset" when you refresh the bindings.


if you know to call refresh(), why not just go ahead and refresh the ui at that point anyway?

propertychanging and propertychanged are invoked by invoking the setter on a linqtosql dbml-generated entity class. calling refresh() does not do that:

[column(storage="_displayname", dbtype="varchar(50) not null", canbenull=false)]
public string displayname
        return this._displayname;
        if ((this._displayname != value))
            this._displayname = value;

Related Query

More Query from same tag