/// <summary>
        /// Builds the filter expression and raises the FilterExpressionBuilding event
        /// </summary>
        /// <param name="sender">The event source.</param>
        /// <param name="e">The <see cref="System.ComponentModel.CancelEventArgs"/> userPermissions containing the event data.</param>
        /// <remarks>
        /// Override <b>OnFilterExpressionBuilding</b> to provide a filter expression construction
        /// logic and to set the values of the <see cref="DgvBaseColumnFilter.FilterExpression"/> and <see cref="DgvBaseColumnFilter.FilterCaption"/> properties.
        /// The <see cref="DgvFilterManager"/> will use these properties in constructing the whole filter expression and to change the header text of the filtered column.
        /// Otherwise, you can create an event handler and set the <i>Cancel</i> ctl of event argument to true, to skip standard filter expression building logic.
        /// </remarks>
        protected override void OnFilterExpressionBuilding(object sender, CancelEventArgs e)
        {
            base.OnFilterExpressionBuilding(sender, e);

            if (e.Cancel)
            {
                FilterManager.RebuildFilter();
                return;
            }

            FilterResult filterResult = new FilterResult();
            filterResult.Caption = this.OriginalDataGridViewColumnHeaderText;

            if (this.checkBoxSelectNull.Checked)
            {
                filterResult.Expression = GetNullCondition(this.DataGridViewColumn.DataPropertyName);
                filterResult.Caption += "\n= Ø";
            }

            if (this._checkedItems.Count > 0)
            {
                if (!String.IsNullOrEmpty(filterResult.Expression))
                    filterResult.Expression += " OR ";

                filterResult.Expression += this.DataGridViewColumn.DataPropertyName + " IN (";
            }

            Int32 i = 0;

            foreach (String filter in this._checkedItems)
            {
                if (!String.IsNullOrEmpty(filter))
                    filterResult = this.ApplyFilter(filterResult, filter, i);

                i++;
            }

            if (this._checkedItems.Count > 0)
                filterResult.Expression += filterResult.Expression.Substring(0, filterResult.Expression.Length - 1) + ")";

            if (i > this.MaxCaptionItems)
                filterResult.Caption += "\n...";

            if (!String.IsNullOrEmpty(filterResult.Expression))
            {
                FilterExpression = filterResult.Expression;
                FilterCaption = filterResult.Caption;
                FilterManager.RebuildFilter();
            }
            else
            {
                FilterManager.ActivateFilter(false, this.DataGridViewColumn.Index);
            }
        }
        /// <summary>
        /// Builds the filter expression and raises the FilterExpressionBuilding event
        /// </summary>
        /// <param name="sender">The event source.</param>
        /// <param name="e">The <see cref="System.ComponentModel.CancelEventArgs"/> userPermissions containing the event data.</param>
        /// <remarks>
        /// Override <b>OnFilterExpressionBuilding</b> to provide a filter expression construction
        /// logic and to set the values of the <see cref="DgvBaseColumnFilter.FilterExpression"/> and <see cref="DgvBaseColumnFilter.FilterCaption"/> properties.
        /// The <see cref="DgvFilterManager"/> will use these properties in constructing the whole filter expression and to change the header text of the filtered column.
        /// Otherwise, you can create an event handler and set the <i>Cancel</i> ctl of event argument to true, to skip standard filter expression building logic.
        /// </remarks>
        protected override void OnFilterExpressionBuilding(object sender, CancelEventArgs e)
        {
            base.OnFilterExpressionBuilding(sender, e);

            if (e.Cancel)
            {
                FilterManager.RebuildFilter();
                return;
            }

            FilterResult filterResult = new FilterResult();

            filterResult.Caption = this.OriginalDataGridViewColumnHeaderText;

            if (this.checkBoxSelectNull.Checked)
            {
                filterResult.Expression = GetNullCondition(this.DataGridViewColumn.DataPropertyName);
                filterResult.Caption   += "\n= Ø";
            }

            if (this._checkedItems.Count > 0)
            {
                if (!String.IsNullOrEmpty(filterResult.Expression))
                {
                    filterResult.Expression += " OR ";
                }

                filterResult.Expression += this.DataGridViewColumn.DataPropertyName + " IN (";
            }

            Int32 i = 0;

            foreach (String filter in this._checkedItems)
            {
                if (!String.IsNullOrEmpty(filter))
                {
                    filterResult = this.ApplyFilter(filterResult, filter, i);
                }

                i++;
            }

            if (this._checkedItems.Count > 0)
            {
                filterResult.Expression += filterResult.Expression.Substring(0, filterResult.Expression.Length - 1) + ")";
            }

            if (i > this.MaxCaptionItems)
            {
                filterResult.Caption += "\n...";
            }

            if (!String.IsNullOrEmpty(filterResult.Expression))
            {
                FilterExpression = filterResult.Expression;
                FilterCaption    = filterResult.Caption;
                FilterManager.RebuildFilter();
            }
            else
            {
                FilterManager.ActivateFilter(false, this.DataGridViewColumn.Index);
            }
        }
        /// <summary>
        /// TODO: Documentation ApplyFilter
        /// </summary>
        /// <param name="filterResult"></param>
        /// <param name="filterText"></param>
        /// <returns></returns>
        private FilterResult ApplyFilter(FilterResult filterResult, String filterText, Int32 index)
        {
            if (index < this.MaxCaptionItems)
                filterResult.Caption += "\n";

            if (ColumnDataType == typeof(String))
            {
                // Managing the string-column case
                String escapedFilterValue = DgvBaseColumnFilter.StringEscape(filterText.ToString());

                filterResult.Expression = String.Format(CultureInfo.CurrentCulture,
                                                        "{0}'{1}',",
                                                        filterResult.Expression,
                                                        escapedFilterValue);

                if (index < this.MaxCaptionItems)
                    filterResult.Caption = String.Format(CultureInfo.CurrentCulture,
                                                         "{0}= {1}",
                                                         filterResult.Caption,
                                                         filterText);
            }
            else
            {
                // Managing the other cases
                String formattedValue = DgvBaseColumnFilter.FormatValue(filterText, this.ColumnDataType);

                if (!String.IsNullOrEmpty(formattedValue))
                {

                    filterResult.Expression = String.Format(CultureInfo.CurrentCulture,
                                                            "{0}{1},",
                                                            filterResult.Expression,
                                                            formattedValue);

                    if (index < this.MaxCaptionItems)
                        filterResult.Caption = String.Format(CultureInfo.CurrentCulture,
                                                             "{0}= {1}",
                                                             filterResult.Caption,
                                                             filterText);
                }
            }

            return filterResult;
        }
        /// <summary>
        /// Builds the filter expression and raises the FilterExpressionBuilding event
        /// </summary>
        /// <param name="sender">The event source.</param>
        /// <param name="e">The <see cref="System.ComponentModel.CancelEventArgs"/> userPermissions containing the event data.</param>
        /// <remarks>
        /// Override <b>OnFilterExpressionBuilding</b> to provide a filter expression construction
        /// logic and to set the values of the <see cref="DgvBaseColumnFilter.FilterExpression"/> and <see cref="DgvBaseColumnFilter.FilterCaption"/> properties.
        /// The <see cref="DgvFilterManager"/> will use these properties in constructing the whole filter expression and to change the header text of the filtered column.
        /// Otherwise, you can create an event handler and set the <i>Cancel</i> ctl of event argument to true, to skip standard filter expression building logic.
        /// </remarks>
        protected override void OnFilterExpressionBuilding(object sender, CancelEventArgs e)
        {
            base.OnFilterExpressionBuilding(sender, e);

            if (e.Cancel)
            {
                this.FilterManager.RebuildFilter();
                return;
            }

            String resultFilterCaption    = this.OriginalDataGridViewColumnHeaderText + "\n";
            String resultFilterExpression = String.Empty;

            // Managing the NULL and NOT NULL cases which are entityType-independent
            if (this.comboBoxOperator.Text == "= Ø")
            {
                resultFilterExpression = DgvBaseColumnFilter.GetNullCondition(this.DataGridViewColumn.DataPropertyName);
            }

            if (this.comboBoxOperator.Text == "<> Ø")
            {
                resultFilterExpression = DgvBaseColumnFilter.GetNotNullCondition(this.DataGridViewColumn.DataPropertyName);
            }

            if (!String.IsNullOrEmpty(resultFilterExpression))
            {
                this.FilterExpression = resultFilterExpression;
                this.FilterCaption    = resultFilterCaption + "\n" + this.comboBoxOperator.Text;
                this.FilterManager.RebuildFilter();

                return;
            }

            FilterResult filterResult = new FilterResult();

            filterResult = this.ApplyFilter(filterResult,
                                            this.comboBoxOperator,
                                            this.textBoxValue.Text,
                                            null);

            foreach (FilterComponents filter in this._filters)
            {
                if (!String.IsNullOrEmpty(filter.TextBoxValue.Text))
                {
                    filterResult = this.ApplyFilter(filterResult,
                                                    filter.ComboBoxOperator,
                                                    filter.TextBoxValue.Text,
                                                    filter.ComboBoxAndOr.Text);
                }
            }

            resultFilterExpression = filterResult.Expression;
            resultFilterCaption   += filterResult.Caption;

            if (!String.IsNullOrEmpty(resultFilterExpression))
            {
                this.FilterExpression = resultFilterExpression;
                this.FilterCaption    = resultFilterCaption;
                this.FilterManager.RebuildFilter();
            }
        }