.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Persist sort order in datagrid

Posted By:      Posted Date: September 30, 2010    Points: 0   Category :WPF


I've got multiple datagrids in the application I'm currently working on. Their ItemSource can be updated with new content on server notifications. When this happens, the ItemSource is being replaced by a new one (would it be better to update the content of the ItemSource - which is much more complicated for this case of figure - instead of binding a new one?)

When the new ItemSource is being bound, the sorting of the grid is being lost. I've solved this behaviour by saving the sorting before setting the new binding and restoring it after the new binding has been done. Below you'll find the static methods used for that:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Windows.Controls;
using System.Windows.Data;
using Telecontrol.SIPPR.Client.Commons.DataObjects;

namespace Telecontrol.SIPPR.Client.Commons.Utils
  public static class DataGridUtil

View Complete Post

More Related Resource Links

What is the meaning of Ascending\descending sort order of a column within an index

When I add a new index I can also specify the "sort order" as ascending or descending. What does it mean? does it affect performance? does it mean that the binary search tree will be set in a certain way?

Dynamic Data Entity Framework: Initial Sort Order for Views

Hello Steve,I'm trying to set an initial sort order for my View (not table) in Dynamic Data using Entity Framework 2. I have updated my Model and Imported the View. Now I'm trying to use the DisplayColumn attibutebut it's not working.[DisplayColumn("Product", "ParsingOrder", true)]Fabio

Sort a WPF DataGrid on a Customized Column

I have several wpf DataGrids that use something similar to: {     Binding Path=ContactID, Converter={StaticResource contactIDToNameConverter}}"       As a best concept for various ID fields in my database.  This is great when needing to display editable data that is linked by ID, and my converter handles the validation and cleanup if needed. Otherwise an SQL View, or Joined Table SQL would not be able to send updates directly to the database (DataSet Wizard).  For this DataGrid's Contact column (bound to the ContactID field from a ICollectionView; bound to a DataSet.ClientsToContacts DataTable), I have an underlying value of Integer, and a converted surface value of String.  I want to sort on the string. Using ICollectionView.View.SortDescription(path,direction) will only sort on the Integer, and I am desprately seeking work arounds.  Please help. jvj

WCF DataService : basic Order - OderDetail - Product use case - unable to persist

Hello, I have the very classical Order - OderDetail - Product use case. I've made my database, my entity framework model and exposed it as a DataServices Read/Write. Order, OrderDetail and Product table have a Id column which is a PK based on an IDENTITY column (auto incr) Form the client, I try the following : MyEntities session1 = new MyEntities(svcUri); Order o = new Order(); session1.AddToOrder(o); o.OrderDate = DateTime.Now; Product p1 = new Product(); session1.AddToProduct(p1); p1.ProductDescription = "Product1"; Product p2 = new Product(); session1.AddToProduct(p2); p2.ProductDescription = "Product2"; OrderDetails d1 = new OrderDetails() {Product = p1, Amount = 1}; session1.AddToOrderDetails(d1); o.OrderDetails.Add(d1); var response1 = session1.SaveChanges(SaveChangesOptions.Batch); I receive the following error : Unable to determine the principal end of the 'MyEntities.FK_OrderDetails_Product' relationship. Multiple added entities may have the same primary key. I try to initialize every Id (PK)  of every object I create on the client using temporary values (-1,-2,-3,...) and then I got an other error message : The INSERT statement conflicted with the FOREIGN KEY constraint \"FK_OrdeDetails_Order\". The conflict occurred in database \"MyEntities\", table \"dbo.Order\", column 'OrderId'.&a

Dundas Map - Legend sort order

ello, We are using Dundas Maps together with Reporting Services 2008. Now we have come across a problem which we are not able to solve ourselves.   We produce a map showing each countries “ReportingFormat”. The SQL in the background  has the “order by ReportFormat” clause.   The values available in “ReportFormat” are shown in the legend. So far everything looks fine and the values within the legend are ordered correctly (E2B, Intdis, Not specified). See the picture http://img340.imageshack.us/i/correctorderfrompreview.jpg/   We therefore deploy the report and open it up in Internet Explorer but now the order of the legend has changed and is shown as (Intdis, Not specified, E2B). See the picture http://img816.imageshack.us/i/incorrectorderfromie.jpg/   We have tried to set the sorting also within the map (not only within the SQL) but the same problem remained although we are not sure we set that sorting correctly . We are not sure that we found the series collection where we could set the sort order. It is all a bit confusing when working with the maps.   As a final solution we tried to change the available values in “ReportFormat” but then the order was even more confusing. See table below; Available values (ReportFormat) Order in legend in Visual studio preview Order in legend in Internet

order by sort both select in union



I have DropDownList that Show all groups. in that, I want to show "select one group" as default in DDL. for that i used code below. but it sort all return data and "select one group" will not be the first line. How can i fix it?

Best Regards. Morteza


	SELECT   -1 as id,'select one group' as groupName
	SELECT   id, groupName
	FROM     [group] 
	order by groupNam

SSRS 2005 and Sort Order

I have a table and want to sort the 1st column which is called "WorkType" in a particular order. At present it looks like this.

Admin Tasks
Leave & Public Holiday

managed metadata sort order for swedish


Sort order for managed metadata is not as expected, for instance Swedish letters Å and Ä are sorted as A

The properties for the standard language is set to swedish and explicit sort order is not set.

Is this a bug, or are we doing something wrong?


Microsoft SharePoint Server 2010 (14.0.4763.1000)

Language Pack for SharePoint, Project Server and Office Web Apps 2010 - Swedish/svenska (14.0.4763.1000)

Sort WPF Datagrid using multiple columns



Is it possible to sort a WPF datagrid using more than one column ?



SharePoint 2010 library sort order is incorrect.


When sorting by name in a SharePoint 2010 library, numeric results are sorting incorrectly. For instance "122_Test" will sort in front of "13_Test". I know at one point years ago Windows Explorer had the same issue, but when viewing the same library by using the Open with Explorer option, Windows Explorer correctly displays the results. Has anyone encountered this issue, and if so have you found a fix?


Tim Vander Kooi

In RB 2.0 how to sort in ascending/descending order as default?

I have column say of Provider Type which I want to be ordered when report is run so that all other columns are ordered according to the order of the Provider Type values.

WPF: how to make a GridView only sort on one column as ascending order?


We use GridView inside the Listview. We need the grid view alwasy sort on one column ascending order and not allow to click column header to change it.

Is there a easy way to achieve it in Xaml?

If not possible, how to achieve it in code behind?



Datatable sort in a particular order


How do I sort a data table based on a particular column which has integer values in ascending order?


I wrote this:

leadtable.DefaultView.Sort = "Id"

But it doesnt seem to work, it displays fine but when i get try to get the values of the sorted datatable in an array they dont come in an sorted ordere

Datatble is defined as:


  • leadtable = New DataTable("LeadTable")   
  •         Dim leadid As New DataColumn("Id")   
  •         leadi
  • WPF datagrid Tab Navigation problem not following tab index order



    I have designed a wpf page with 3 textbox than a datagrid than again a text box

    and I have set the tabindex to first 3 testbox 1, 2, 3, than 4 to datagrid and 5 to last testbox

    But when I run page and press tab to navigate,first three textbox are ok they follow tabindex but when I tab to navigate to datagrid it jumps to forth textbox and again on next tab go to datagrid. means after navigating all of the four textbox its go to girdview.

    Please tell me how I can set tab order?

    How can I use ORDER BY by passing different columns and sort orders?


    Hi all

    Here is what I am trying to do:

    declare @dateBegin as datetime, @dateEnd as datetime
    declare @column as varchar(30), @order as varchar(4)
    set @dateBegin = null
    set @dateEnd  = null
    set @column  = 'created'
    set @order   = 'DESC'
    	(@dateBegin is null or startTime >= @dateBegin) and (@dateEnd is null or endTime <= @dateEnd)

    WPF datagrid Tab Navigation problem not following tab index order



    I have designed a wpf page. But I not able to set Proper Tab Navigation on it. Controls (Specialy datagrid) on the page are not following tab index. 

    It has a group box inside which there is a grid. this grid has rows and columns. In first three rows contains textboxes. 4th row contains  the datagrid forth row spans to 5 cols. in next row it agains has textbox and after that it has 3 buttons

    Following is the design view, Run time view with tabindex which I have given to them and arrows show the index they are following.

    I am loading datagrid with a object of list of items which has one object of type item. so as per my thinking it is not empty it has data in it. as you can see in run time view

    ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
    Sql Server  SharePoint  Silverlight  Others  All   

    Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend