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 System.ComponentModel;
using System.Linq;
using System.Diagnostics;

namespace Test.GridSorting
{
    public class Data : INotifyPropertyChanged
    {
        private static PropertyChangedEventArgs args = new PropertyChangedEventArgs("Value");
        private string _firstName;
        private string _lastName;
        private uint _age;
        private DateTime _birthDay;
        private double _value;

        public double Value
        {
            get { return _value; }
            set
            {
                if (_value != value)
                {
                    _value = value;
                    OnPropertyChanged(args);
                }
            }
        }

        public string FirstName
        {
            get { return _firstName; }
            set
            {
                if (_firstName != value)
                {
                    _firstName = value;
                    OnPropertyChanged(new PropertyChangedEventArgs("FirstName"));
                }
            }
        }

        public string LastName
        {
            get { return _lastName; }
            set
            {
                if (_lastName != value)
                {
                    _lastName = value;
                    OnPropertyChanged(new PropertyChangedEventArgs("LastName"));
                }
            }
        }

        public DateTime Birthday
        {
            get { return _birthDay; }
            set
            {
                if (_birthDay != value)
                {
                    _birthDay = value;
                    OnPropertyChanged(new PropertyChangedEventArgs("BirthDay"));
                }
            }
        }

        public uint Age
        {
            get { return _age; }
            set
            {
                if (_age != value)
                {
                    _age = value;
                    OnPropertyChanged(new PropertyChangedEventArgs("Age"));
                }
            }
        }

        public override string ToString()
        {
            return string.Format("{0} -> {1}", _firstName, _value);
        }


        private void OnPropertyChanged(PropertyChangedEventArgs args)
        {
            PropertyChanged(this, args);
            //Delegate[] delegates = _propertyChanged.GetInvocationList();
            //foreach (Delegate del in delegates)
            //{
            //    if (_propertyChanged.GetInvocationList().Contains(del))
            //    {
            //        del.DynamicInvoke(this, args);
            //    }
            //}
        }

        
        public event PropertyChangedEventHandler PropertyChanged = delegate{};
        //{
        //    add
        //    {
        //        //int count = _propertyChanged.GetInvocationList().Count<Delegate>(d => d.Method == value.Method);
        //        //if(count < 5)
        //        {
        //            _propertyChanged += value;
        //            Debug.WriteLine(string.Format("{1} Add Handlers : {0}", _propertyChanged.GetInvocationList().Length, _firstName));
        //        }
        //    }
        //    remove
        //    {
        //        _propertyChanged -= value;
        //        Debug.WriteLine(string.Format("{1} Remove Handlers : {0}", _propertyChanged.GetInvocationList().Length, _firstName));
        //    }
        //}

    }

}

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
Web04 | 2.8.140926.1 | Last Updated 29 Jan 2009
Article Copyright 2009 by Stefan Bocutiu
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid