score:3

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:

collectionviewsource.getdefaultview(treeviewclusters.itemssource).refresh();

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())
     sendpropertychanged(prop.name);
}

the you can just call this in your application code:

context.refresh(refreshmode.overwritecurrentvalues, employee);
employee.sendpropertieschanged();

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.

score:0

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
{
    get
    {
        return this._displayname;
    }
    set
    {
        if ((this._displayname != value))
        {
            this.ondisplaynamechanging(value);
            this.sendpropertychanging();
            this._displayname = value;
            this.sendpropertychanged("displayname");
            this.ondisplaynamechanged();
        }
    }
}

Related Query

More Query from same tag