Home Forums WPF controls Xceed DataGrid for WPF IBindingList and Sorting

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

    I have a collection that implements IBindingList that isn’t being sorted correctly. When I click on a column header on a grid that contains 4 rows and an insert row, “SupportsSorting” is called 10 times (it always returns true), but ApplySort is never called.

    Imported from legacy forums. Posted by mkb137 (had 898 views)

    Xceed Support
    Member
    Post count: 5658

    Could you post (or send to support to my attention) your IBindingList implementation?

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

    Xceed Support
    Member
    Post count: 5658

    The sorting did not function in the grid; however it also did not function in the ListView control. I think you may need to verify your implementation or, if you prefer, simply wrap your collection in a DataGridCollectionView (which worked).

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

    User (Old forums)
    Member
    Post count: 23064

    ListViews don’t support sorting via clicks of a GridView’s column header, no matter what the underlying source is.

    I could theoretically have written a bad IBindingList implementation, and if I did, chances are that ApplySort would fail somehow. But the DataGrid never calls ApplySort. Why?

    Imported from legacy forums. Posted by mkb137 (had 662 views)

    User (Old forums)
    Member
    Post count: 23064

    Here’s an IBindingList implementation that does the bare minimum:
    <pre>
    class MyBindingList<T> : List<T>, IBindingList {
    #region IBindingList Members
    public void AddIndex( PropertyDescriptor property ) {
    throw new Exception( “The method or operation is not implemented.” );
    }
    public object AddNew() {
    throw new Exception( “The method or operation is not implemented.” );
    }
    public bool AllowEdit {
    get { throw new Exception( “The method or operation is not implemented.” ); }
    }
    public bool AllowNew {
    get { throw new Exception( “The method or operation is not implemented.” ); }
    }
    public bool AllowRemove {
    get { throw new Exception( “The method or operation is not implemented.” ); }
    }
    public void ApplySort( PropertyDescriptor property, ListSortDirection direction ) {
    Console.WriteLine( “ApplySort – property = {0}, direction = {1}”, property, direction );
    throw new Exception( “The method or operation is not implemented.” );
    }
    public int Find( PropertyDescriptor property, object key ) {
    throw new Exception( “The method or operation is not implemented.” );
    }
    public bool IsSorted {
    get { throw new Exception( “The method or operation is not implemented.” ); }
    }
    public event ListChangedEventHandler ListChanged;
    public void RemoveIndex( PropertyDescriptor property ) {
    throw new Exception( “The method or operation is not implemented.” );
    }
    public void RemoveSort() {
    throw new Exception( “The method or operation is not implemented.” );
    }
    public ListSortDirection SortDirection {
    get { throw new Exception( “The method or operation is not implemented.” ); }
    }
    public PropertyDescriptor SortProperty {
    get { throw new Exception( “The method or operation is not implemented.” ); }
    }
    public bool SupportsChangeNotification {
    get {
    Console.WriteLine( “SupportsSorting” );
    return true;
    }
    }
    public bool SupportsSearching {
    get { throw new Exception( “The method or operation is not implemented.” ); }
    }
    public bool SupportsSorting {
    get {
    Console.WriteLine( “SupportsSorting” );
    return true;
    }
    }
    #endregion
    }
    </pre>

    The only methods it supports are “SupportsChangeNotification” and “SupportsSorting”. This list can be used as the data source of a DataGrid with no exceptions being thrown on load or even when the column header is clicked. The column header does add the up and down arrows to indicate that the grid thinks sorting is being done. I would expect that if the DataGrid knew that the source was an IBindingList that supports sorting, ApplySort would be called.

    Imported from legacy forums. Posted by mkb137 (had 4141 views)

    User (Old forums)
    Member
    Post count: 23064

    Hi,

     I am new to all this stuff,so pls bear with me. I want the columns to be sorted , my xaml code says:

    <

    UI:DataGrid.View>

    <!– Default view –>

    <xceed:TableView UseDefaultHeadersFooters=”False”>

    <xceed:TableView.FixedHeaders>

    <DataTemplate>

    <xceed:ColumnManagerRow AllowSort=”True” AllowColumnReorder=”False”/>

    </DataTemplate>

    </xceed:TableView.FixedHeaders>

    </xceed:TableView>

    </UI:DataGrid.View>

     

    My code behind says:

    public

    class DataCollection : CollectionBase, IBindingList, ITypedList

    All the methods have been implemented as below:

    public void AddIndex(PropertyDescriptor property)

    {

    throw new NotSupportedException();

    }

    public object AddNew(){

    Data dataEntry = new Data();

    Add(dataEntry);

    return dataEntry;}

    public bool AllowEdit{

    get{

    return true;}

    }

    public bool AllowNew{

    get{

    return true;}

    }

    public bool AllowRemove{

    get{

    return true;}

    }

    public void ApplySort(PropertyDescriptor property, ListSortDirection direction){

    throw new NotSupportedException();

    }

    public int Find(PropertyDescriptor property, object key)

    {

    throw new NotSupportedException();

    }

    public bool IsSorted{

    get{

    throw new NotSupportedException();}

    }

    private ListChangedEventHandler m_ListChanged;

    public event ListChangedEventHandler ListChanged{

    add{

    m_ListChanged -=

    value;

    m_ListChanged +=

    value;}

    remove{

    m_ListChanged -=

    value;}

    }

    public void Remove(DatadataEntry){

    if (List.Count > 0 && dataEntry != null){

    List.Remove(dataEntry);

    }}

    public void RemoveIndex(PropertyDescriptor property)

    {

    throw new NotSupportedException();

    }

    public void RemoveSort()

    {

    throw new NotSupportedException();

    }

    public ListSortDirection SortDirection{

    get{

    throw new NotSupportedException();}

    }

    public PropertyDescriptor SortProperty{

    get{

    throw new NotSupportedException();}

    }

    public bool SupportsChangeNotification{

    get{

    return true;}

    }

    public bool SupportsSearching{

    get{

    return false;}

    }

    public bool SupportsSorting{

    get{

    return false;}

    }

    I am little confused that in this case the property “SupportsSorting” returns false so it does not let me do sorting on the columns even though I have allowSort=”true” in xaml.

    If I return the value of the above property as true then it goes to ApplySort method and throws exception. Do I need to call an explicit sorting method from the above method?

     

    Imported from legacy forums. Posted by BhartiV (had 1788 views)

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