Example #1
0
        /// <summary>
        /// Check a compare result against a filter type.  We use
        /// the internal CompareData and ItemText methods to get
        /// the correct text and perform the comparison using the
        /// filter column datatype.  The result from CompareData
        /// is used to check against the Type of filtering applied.
        /// The f (LVFFilter) has been prepared with all the data
        /// about the filtering to be performed; column, text,
        /// datatype, and filtering type by FilterBuild().
        /// </summary>
        /// <param name="r">Result -1/0/1</param>
        /// <param name="f">LVFFilter</param>
        /// <returns></returns>
        private bool FilterCheck( ListViewItem i, LVFFilter f )
        {
            // get the result of the data type comparison
            TypedColumnHeader header = this.Columns[ f.Column ] as TypedColumnHeader;
            Debug.Assert( header != null );

            int r = header.CompareData( header.GetData( i ), f.Data, _ignoreCase );

            // compare the result against the filter comparison type
            // a true result means that it passed filtering and should
            // be left in the list of filtered items.
            switch( f.Compare )
            {
                case LVFFilterType.Equal:
                    return ( r == 0 );
                case LVFFilterType.NotEqual:
                    return ( r != 0 );
                case LVFFilterType.Greater:
                    return ( r > 0 );
                case LVFFilterType.GreaterEqual:
                    return ( r >= 0 );
                case LVFFilterType.Less:
                    return ( r < 0 );
                case LVFFilterType.LessEqual:
                    return ( r <= 0 );
                default:
                    return ( r == 0 );
            }
        }
Example #2
0
        /// <summary>
        /// Create a new filter entry for the given column.  This
        /// will replace/add a LVFFilter instance for the column
        /// to the itm_filtrs array for use by FilterUpdate().
        /// </summary>
        /// <param name="c">Column number</param>
        private void FilterBuild( int c )
        {
            // if this column exists in the filters array remove it
            foreach( LVFFilter f in _filters )
                if( f.Column == c )
                {
                    _filters.Remove( f );
                    break;
                }

            // get the filter text for this column from the header
            string s = _headerControl.Filter[ c ].Trim();

            // if there is any size to it then create a new filter
            if( s.Length > 0 )
            {

                // create a new filter object for this column
                LVFFilter f = new LVFFilter();
                f.Column = c;
                f.Text = s;
                f.Compare = LVFFilterType.Equal;
                f.Type = _headerControl.DataType[ c ];

                // check the first characters of the string to see
                // if this is not a default equality comparison
                switch( s[ 0 ] )
                {
                    case '=':
                        f.Text = s.Remove( 0, 1 );
                        break;
                    case '!':
                        f.Compare = LVFFilterType.NotEqual;
                        f.Text = s.Remove( 0, 1 );
                        break;
                    case '>':
                        if( ( s.Length > 1 ) && ( s[ 1 ] == '=' ) )
                        {
                            f.Compare = LVFFilterType.GreaterEqual;
                            f.Text = s.Remove( 0, 2 );
                        }
                        else
                        {
                            f.Compare = LVFFilterType.Greater;
                            f.Text = s.Remove( 0, 1 );
                        }
                        break;
                    case '<':
                        if( ( s.Length > 1 ) && ( s[ 1 ] == '=' ) )
                        {
                            f.Compare = LVFFilterType.LessEqual;
                            f.Text = s.Remove( 0, 2 );
                        }
                        else
                        {
                            f.Compare = LVFFilterType.Less;
                            f.Text = s.Remove( 0, 1 );
                        }
                        break;
                }

                // add this to the array of filters
                _filters.Add( f );

            }
        }