score:3
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();
}
}
}
Source: stackoverflow.com
Related Query
- DataContext Refresh and PropertyChanging & PropertyChanged Events
- Entity Framework, Code First and Full Text Search
- What does this C# code with an "arrow" mean and how is it called?
- How to count the number of code lines in a C# solution, without comments and empty lines, and other redundant stuff, etc?
- I am wondering about the state of connection and impact on code performance by 'yield' while iterating over data reader object
- Enumerable.Empty<T>().AsQueryable(); This method supports the LINQ to Entities infrastructure and is not intended to be used directly from your code
- LINQ Source Code Available
- Refactor Linq code and "LINQ to Entities does not recognize the method"
- .NET 4 Code Contracts: "requires unproven: source != null"
- Performance tuning C# permutations and SHA1 code
- What is the difference between ((IEnumerable)source).OfType<T>() and source as IEnumerable<T>
- How can I code an outer join using LINQ and EF6?
- Avoid extra loop and could not find implementation of query pattern for source type int Select not found
- LINQ: Relations do not get updated after SubmitChanges and Refresh
- Creating database using DataContext and System.Data.SQLite in C#
- Determine the source DataContext for a Linq to Sql query
- Linq Datacontext and "unit of work"
- Why not reveal the type and identity of the source to the client?
- C# - Linq optimize code with List and Where clause
- IEqualityComparer and Linq Distinct - Hard Code GetHashCode()
- EF Code first Eager loading and OrderBy problem
- Code Example for Add DateTime and TimeSpan in EF query
- creating Linq to sqlite dbml from DbLinq source code
- Stubbing Code for Test With Linq Expressions and Lambdas
- LINQ: DataContext Life and System.Data.SqlClient.SqlException: Timeout expired
- How to get and use source of grouping in LINQ?
- Handling very large strings between SQL Server and .NET code +LINQ
- SQL subquery result in LINQ and Entity Framework Code First
- Is there a way to call ExecuteQuery on a SQL DataContext and return a Tuple instead of a class/object
- How to change the precision and the scale of decimal globally through code first?
More Query from same tag
- enumerated more than once in linq to sql stored procedure call
- How to get data related to sets of different combinations dynamically
- Replace duplicates in array of strings
- Reading data from xml and writing in database using C#
- Converting linq-to-xml query from vb to c#
- How can I sum value of duplicate row and show in gridview?
- Compare dd-mm-yyyy datetime
- Calling a custom method in LINQ query
- Dynamically querying 2 entity types and mapping results back into specific entity set
- How to remove duplicates from a List of List using Linq
- Splitting a deferred IEnumerable<T> into two sequences without re-evaluation?
- LINQ and optional parameters
- Translating a sql Case When statement to LINQ
- Efficient linq query to return objects when you have a list of object id's
- copying double[] values into an entire column in a datatable rapidly
- Why IEnumerable slow and List is fast?
- SQL Query continues running for a very long time if search term not found
- Unzip objects collection into arrays of its properties
- LINQ Entity Framework Value cannot be null. Parameter name: String
- Translating SQL Queries to LINQ
- Using LINQ to organize database result
- transform value of Dictionary using lambda
- Find an object within a list and replace its value
- Finding Last Name Using LINQ
- How to remove duplicates in the middle
- Linq to Entities - Contains not working
- C# Linq Select from one to many but if in the many one is false dont return
- Defining a one-to-one relationship in SQL Server
- How to extend predicate in lambda expression parameter
- Linq Expressions for Indexer Properties