Question

I want to create a bindingSource that supports sorting by multiple columns and attach it to a bindingNavigator. I am using winforms and code-first EF.

I am constructing my query in the following manner

DbSet<Person> dset = DBContext.People;
string Searchstr ="Smith";
string sortby ="LastName, FirstName"
var qry = (IOrderedQueryable<Person>) dset.Where(
                            p => p.LastName.Contains(Searchstr) )
                            .OrderBy(sortby);

binding.datasource = dset.Local.ToBindingList();   // where binding has been dropped on form at design time.
binding.sort = sortby;   // this is the line that screws up the sort order

I am using the extension method documented here to achieve the multi-column order by.

Was it helpful?

Solution

The problem turned out to be that I had set binding.sortby =sortby. Using the multi column sortby was OK in the query because of the clever extension ( see link in the question) however it does not work to set the binding.sort to an expression involving multiple columns The code works fine if I remove that line.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top