Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version
Go to top

Auto-filter for Microsoft WPF DataGrid

, 29 Jan 2009
Allows auto filtering functionality for DataGrid columns.
WPFGridFilter.zip
WPFGridFilter
PowerCollections
PowerCollections.csproj.user
Properties
Stepi.Collections
bin
Filters
Properties
Stepi.UIFilters
bin
Initializers
Properties
Settings.settings
Themes
Test.GridSorting
bin
Debug
Test.GridFilter.vshost.exe
Properties
Settings.settings
using System;
using Stepi.Collections;
using Stepi.Collections.Filters;
using System.ComponentModel;

namespace Stepi.UIFilters
{
    public class CompareFilterPresentationModel<T> : ICompareFilterPresentationModel<T>
        where T : IComparable
    {
        private static readonly PropertyChangedEventArgs _activeEventArgs = new PropertyChangedEventArgs("IsActive");
        private static readonly PropertyChangedEventArgs _applyEventArgs = new PropertyChangedEventArgs("CanApply");

        private bool _targetError;
        private bool _isActive;
        private bool _canApply = true;
        private readonly ICompareFilter<T> _filter;
        private readonly string _name;

        public event PropertyChangedEventHandler PropertyChanged = delegate { };

        public CompareFilterPresentationModel(ICompareFilter<T> compareFilter, string name)
        {
            if (compareFilter == null)
            {
                throw new ArgumentNullException("compareFilter");
            }
            _name = name;
            _filter = compareFilter;
        }

        public T Target
        {
            get
            {
                return _filter.CompareTo;
            }
            set
            {

                _filter.CompareTo = value;
            }
        }

        public string Name
        {
            get { return _name; }
        }

        object ICompareFilterPresentationModel.Target
        {
            get
            {
                return _filter.CompareTo;
            }
            set
            {
                _targetError = false;
                if (!(value is T))
                {
                    _targetError = true;
                    IsActive = false;
                    return;
                }

                _filter.CompareTo = (T)value;

            }
        }

        public IFilter Filter
        {
            get { return _filter; }
        }

        public bool CanApply
        {
            get { return _canApply; }
            set
            {
                if (_canApply != value)
                {
                    _canApply = value;
                    PropertyChanged(this, _applyEventArgs);
                }
            }
        }

        public bool IsActive
        {
            get
            {
                return _isActive;
            }
            set
            {
                if (_isActive != value)
                {
                    _isActive = value;
                    PropertyChanged(this, _activeEventArgs);
                }
            }
        }

        public void UpdateData(bool isDisplaying)
        { }

    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Eclipse Public License 1.0

Share

About the Author

Stefan Bocutiu
Software Developer (Senior) Lab49
United Kingdom United Kingdom
No Biography provided

| Advertise | Privacy | Mobile
Web01 | 2.8.140916.1 | Last Updated 29 Jan 2009
Article Copyright 2009 by Stefan Bocutiu
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid