Home Forums WPF controls Xceed DataGrid for WPF Sorting columns from code behind

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #24858 |

    Hi,
    At the moment on the Column class there are SortINdex and SortDirection properties, but they are readonly. Is there anyway i can set the sorting from the code behind.

    Thanks.

    Imported from legacy forums. Posted by abatti (had 699 views)

    User (Old forums)
    Member
    Post count: 23064

    I should mention i am binding to an observable list.

    Thanks.

    Imported from legacy forums. Posted by abatti (had 211 views)

    Xceed Support
    Member
    Post count: 5658

    You can add SortDescription objects to the SortDescriptions property of the DataGridCollectionView. If you are not using the DataGridCollectionView as a source (which contains your ObservableList) then you can add SortDescription objects directly to the Items property of the grid (which is an ItemsControl).

    <a href=”http://doc.xcd/XceedWpfDataGrid/Sorting%20Data.html”>Sorting with DataGridCollectionView</a> (the examples are in XAML, but it should point you in the right direction. Just maje sure you use DataGridCollectionView and not DataGridCollectionViewSource)

    <a href=”ms-help://MS.MSSDK.1033/MS.NETFX30SDK.1033/cpref30/html/P_System_Windows_Controls_ItemCollection_SortDescriptions.htm”>ms-help://MS.MSSDK.1033/MS.NETFX30SDK.1033/cpref30/html/P_System_Windows_Controls_ItemCollection_SortDescriptions.htm</a>

    Imported from legacy forums. Posted by Jenny [Xceed] (had 314 views)

    User (Old forums)
    Member
    Post count: 23064

    Thank you. This was helpful.

    Imported from legacy forums. Posted by abatti (had 263 views)

    User (Old forums)
    Member
    Post count: 23064

    That link appears to be broken…

    I’ve created an event handler for the SortDescriptions but now I want to work with the column that triggered the even but don’t understand how to do this. The event handler is as follows:

    ((INotifyCollectionChanged)view.SortDescriptions).CollectionChanged +=
    new NotifyCollectionChangedEventHandler(this.SortCollectionChanged);

    protected void SortCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
    {
    //TO DO: grab the sort direction for column that triggered event.
    }

    Any ideas?

    Thank you.
    Jon

    Imported from legacy forums. Posted by Jon (had 4419 views)

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.