Click here to Skip to main content
11,505,486 members (59,245 online)
Click here to Skip to main content
Add your own
alternative version

Auto-filter for Microsoft WPF DataGrid

, 29 Jan 2009 Eclipse 102.9K 4.9K 52
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 System.Collections.Generic;
using System.Reflection;
using Stepi.UIFilters.Initializers;
using System.ComponentModel;

namespace Stepi.UIFilters
{
    public sealed class FilterViewInitializersManager : IFilterViewInitializersManager
    {
        private List<IFilterViewInitializer> _initializers;

        public FilterViewInitializersManager()
        {
            _initializers = new List<IFilterViewInitializer>();

            _initializers.Add(new EqualFilterInitializer());
            _initializers.Add(new GreterOrEqualFilterInitializer());
            _initializers.Add(new LessOrEqualFilterInitializer());
            _initializers.Add(new RangeFilterInitializer());
            _initializers.Add(new StringFilterInitializer());
        }

        public FilterViewInitializersManager(IEnumerable<IFilterViewInitializer> initializers)
        {
            if (initializers == null)
            {
                throw new ArgumentNullException("initializers");
            }
            _initializers = new List<IFilterViewInitializer>(initializers);
        }

        #region IFilterViewInitializersManager Members

        public IList<IFilterViewInitializer> Initializers
        {
            get { return _initializers; }
        }

        public IEnumerable<IFilterView> CreateView(PropertyInfo propertyInfo, ICollectionView collection)
        {
            if (propertyInfo == null)
            {
                throw new ArgumentNullException("propertyInfo");
            }
            if (collection == null)
            {
                throw new ArgumentNullException("collection");
            }
            foreach (IFilterViewInitializer initializer in _initializers)
            {
                if (initializer.IsApplying(propertyInfo))
                {
                    yield return initializer.GetFilterView(propertyInfo, collection);
                }
            }
        }

        //public void Register(IFilterViewInitializer viewInitializer)
        //{
        //    if (viewInitializer == null)
        //    {
        //        throw new ArgumentNullException("viewInitializer");
        //    }

        //    if (!_initializers.Contains(viewInitializer))
        //    {
        //        _initializers.Add(viewInitializer);
        //    }
        //}

        //public void Remove(IFilterViewInitializer viewInitializer)
        //{
        //    _initializers.Remove(viewInitializer);
        //}

        //public bool Contains(IFilterViewInitializer viewInitializer)
        //{
        //    return _initializers.Contains(viewInitializer);
        //}

        //public IEnumerable<IFilterViewInitializer> Initializers
        //{
        //    get
        //    {
        //        foreach (IFilterViewInitializer initializer in _initializers)
        //        {
        //            yield return initializer;
        //        }
        //    }
        //}

        #endregion
    }
}

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 | Terms of Use | Mobile
Web03 | 2.8.150520.1 | Last Updated 29 Jan 2009
Article Copyright 2009 by Stefan Bocutiu
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid