Home Forums WPF controls Xceed DataGrid for WPF Error throw when Filter is on & column contains null values

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

    I have been facing some problems with filtering, was wondering if anyone had any ideas about this:

    The following is my code to add columns to ItemSourcesCollection before binding it to the ItemsSource property:-

    DataGridCollectionViewSource view = new DataGridCollectionViewSource();
    view.Source = dataCollection;
    view.ItemProperties.Clear();

    view.AutoFilterMode = AutoFilterMode.And;
    view.DistinctValuesConstraint = DistinctValuesConstraint.Filtered;

    foreach (//loop through a collection of datatable columns)
    {
    DataGridItemProperty itemProperty = new DataGridItemProperty(Header, Name, typeof(string));
    view.ItemProperties.Add(itemProperty);
    }

    However, when I run the code and a particular column contains null objects, an InvalidOperationException occurs – Failed to compare two elements in the array.

    I have discovered the error does not occur if i set:-

    itemProperty.CalculateDistinctValues = false;

    However, by doing so, filtering is not enabled.

    Another workaround with DataGridCollectionView instead of DataGridCollectionViewSource, which should work, as written in the documentation:
    “..the DataGridCollectionView and DataGridCollectionViewSource classes also support automatic filtering, which provides Excel-like end-user filtering according to the distinct values of each column”

    DataGridCollectionView view = new DataGridCollectionView(dataCollection);

    view.ItemProperties.Clear();
    view.AutoFilterMode = AutoFilterMode.And;
    view.DistinctValuesConstraint = DistinctValuesConstraint.Filtered;

    foreach (//loop through a collection of datatable columns)
    {
    DataGridItemProperty itemProperty = new DataGridItemProperty(Header, Name, typeof(string));
    view.ItemProperties.Add(itemProperty);
    }

    However, though no error is thrown for this, filtering is disabled as well.

    Many Thanks!

    Imported from legacy forums. Posted by Serene (had 4639 views)

    Xceed Support
    Member
    Post count: 5658

    I entered a bug report for this issue. We will keep you informed.

    Imported from legacy forums. Posted by Chris [Xceed] (had 533 views)

    Xceed Support
    Member
    Post count: 5658

    It is effectively a bug in version 1.3. It will be fixed in version 2.0, which should be out in the next few months.

    It occurs because in this cases, the DataGridCollectionView converts null to DependencyProperty.UnsetValue rather than simply returning null.

    Thanks for bringing this to our attention.

    Imported from legacy forums. Posted by Chris [Xceed] (had 513 views)

    Xceed Support
    Member
    Post count: 5658

    We’ll let you know when version 2.0 is available

    Imported from legacy forums. Posted by Chris [Xceed] (had 407 views)

    User (Old forums)
    Member
    Post count: 23064

    Tested version 2.0

    It doesn’t return error but an annoying wait cursor take over.

    Not sure if a column’s value contains null in ItemSource, it will make the app mouse cursor change to wait cursor.

    Imported from legacy forums. Posted by Thien Pow (had 505 views)

    Xceed Support
    Member
    Post count: 5658

    Using the code you provided, we were not able to obtain the wait cursor. Would it be possible to send a repro app to support@xceedsoft.com mentioning this forum post. This would helps us investigate this issue further.

    Imported from legacy forums. Posted by Chris [Xceed] (had 462 views)

    Xceed Support
    Member
    Post count: 5658

    This fix is available for <a href=”http://xceed.com/pages/TopMenu/Downloads/Updates.aspx”>download</a&gt;.

    Imported from legacy forums. Posted by CharlesB (had 5838 views)

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