Click here to Skip to main content
15,895,809 members
Articles / Desktop Programming / WPF

Auto-filter for Microsoft WPF DataGrid

Rate me:
Please Sign up or sign in to vote.
4.81/5 (25 votes)
29 Jan 2009Eclipse3 min read 227.1K   8.4K   62  
Allows auto filtering functionality for DataGrid columns.
using System;
using System.ComponentModel;
using System.Windows;

namespace Stepi.UIFilters
{
    /// <summary>
    /// Defines the class used by the multi filter view.
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public class UIFilterValueItem<T> :   IUIFilterValueItem<T>
    {
        private readonly static PropertyChangedEventArgs _selectedChangedArgs = new PropertyChangedEventArgs("IsSelected");

        //private static readonly DependencyProperty IsSelectedProperty;

        //static UIFilterValueItem()
        //{
        //    IsSelectedProperty = DependencyProperty.Register("IsSelected", typeof(bool), typeof(UIFilterValueItem<T>), new PropertyMetadata(false));
        //}

        /// <summary>
        /// the value is selected
        /// </summary>
        private bool _isSelected ;

        /// <summary>
        /// instance of the value
        /// </summary>
        private readonly T _value;

        public event PropertyChangedEventHandler PropertyChanged = delegate { };

        /// <summary>
        /// Initializes a new instance of the <see cref="UIFilterValueItem&lt;T&gt;"/> class.
        /// </summary>
        /// <param name="value">The value.</param>
        public UIFilterValueItem(T value)
        {
            _value = value;
        }

        /// <summary>
        /// Gets or sets a value indicating whether this instance is selected.
        /// </summary>
        /// <value>
        /// 	<c>true</c> if this instance is selected; otherwise, <c>false</c>.
        /// </value>
        public bool IsSelected
        {
            get
            {
                return _isSelected;
                //return (bool) GetValue(IsSelectedProperty);
            }
            set
            {
                //SetValue(IsSelectedProperty, value);
                if (_isSelected != value)
                {
                    _isSelected = value;
                    PropertyChanged(this, _selectedChangedArgs);
                }
            }
        }

        /// <summary>
        /// Gets the value held by this class.
        /// </summary>
        /// <value>The value.</value>
        public T Value
        {
            get
            {
                return _value;
            }
        }


        /// <summary>
        /// Gets the value.
        /// </summary>
        /// <value>The value.</value>
        object IUIFilterValueItem.Value
        {
            get { return Value; }
        }

    }
}

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


Written By
Software Developer (Senior) Lab49
United Kingdom United Kingdom
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions