Welcome to the Xceed Community | Help
Community Search  
More Search Options

Crash on Sorting By Non-existant Column Name

Sort Posts: Previous Next
  •  08-07-2009, 9:08 AM Post no. 23219

    Crash on Sorting By Non-existant Column Name

    Hello, If I set the datasource of the datagrid with one dataset, click on a datagrid header to sort it by a field called "Test", then after I'm done viewing this data I set the datasource of the datagrid to another dataset which does *not* contain a field called "Test", my application crashes; obviously it's still trying to apply the sort to "Test" but that field no longer exists in the new dataset so it crashes. What can I do do prevent this from happening? Also, is there a way to programmatically set the sort column(s)?

    Thanks,

    Anthony

    Filed under: , ,
  •  08-07-2009, 11:03 AM Post no. 23226 in reply to 23219

    Re: Crash on Sorting By Non-existant Column Name

    Hi Anthony,

    For the crash, could you give me the code snippet that you use when changing your data source, as well as the full stack trace of the error?

    As for adding sort columns by code, you need to add them to the DataGridCollectionView's SortCollection.

    For example:

       DataGridCollectionView source = this.myGrid.ItemsSource as DataGridCollectionView;
       source.SortDescriptions.Add( new SortDescription( "ColumnA", ListSortDirection.Ascending ) );
       source.SortDescriptions.Add( new SortDescription( "ColumnB", ListSortDirection.Descending ) );

     


    Diane Lafontaine
    Technical Support / Technical Support Team Lead
    Xceed Software Inc.
View as RSS news feed in XML
Contact | Site Map | Reviews | Legal Terms of Use | Trademarks | Privacy Statement Copyright 2011 Xceed Software Inc.