///// <summary>
        ///// Returns a copy of the specified filter string after removing the part that filters the current column, if present.
        ///// </summary>
        ///// <param name="filter">The filter string to parse.</param>
        ///// <returns>A copy of the specified filter string without the current column's filter.</returns>
        //private String FilterWithoutCurrentColumn(String filter)
        //{
        //    // If there is no filter in effect, return String.Empty.
        //    if (String.IsNullOrEmpty(filter))
        //    {
        //        return String.Empty;
        //    }

        //    // If the column is not filtered, return the filter string unchanged.
        //    if (!filtered)
        //    {
        //        return filter;
        //    }

        //    if (filter.IndexOf(currentColumnFilter) > 0)
        //    {
        //        // If the current column filter is not the first filter, return
        //        // the specified filter value without the current column filter
        //        // and without the preceding " AND ".
        //        return filter.Replace(
        //            " AND " + currentColumnFilter, String.Empty);
        //    }
        //    else
        //    {
        //        if (filter.Length > currentColumnFilter.Length)
        //        {
        //            // If the current column filter is the first of multiple
        //            // filters, return the specified filter value without the
        //            // current column filter and without the subsequent " AND ".
        //            return filter.Replace(
        //                currentColumnFilter + " AND ", String.Empty);
        //        }
        //        else
        //        {
        //            // If the current column filter is the only filter,
        //            // return the empty string.
        //            return String.Empty;
        //        }
        //    }
        //}

        /// <summary>
        /// Updates the BindingSource.Filter value based on a user selection
        /// from the drop-down filter list.
        /// </summary>
        override protected void UpdateFilter(Boolean onlyRefresh = false)
        {
            if (!onlyRefresh)
            {
                // Continue only if the selection has changed.
                if ((filterWindow.cmbConstraint.SelectedIndex == (Int32)m_SelectedConstraintIndex) &&
                    (filterWindow.txtFilterText.Text.Equals(m_SelectedFilterText, StringComparison.InvariantCultureIgnoreCase)))
                {
                    return;
                }

                // Store the new filter value
                m_SelectedConstraintIndex = (ConstraintValues)filterWindow.cmbConstraint.SelectedIndex;
                m_SelectedFilterText      = filterWindow.txtFilterText.Text;
            }

            // Cast the data source to an IBindingListView.
            IBindingListView data =
                this.DataGridView.DataSource as IBindingListView;

            if ((data == null) && (Retriever == null))
            {
                return;
            }

            Debug.Assert((data != null && data.SupportsFiltering) || (Retriever != null),
                         "DataSource is not an IBindingListView or does not support filtering");

            if (data != null)
            {
                throw new NotImplementedException();
                // If the user selection is (All), remove any filter currently
                // in effect for the column.
                //if(selectedFilterValue.Count == filters.Count)
                //{
                //    //data.Filter = FilterWithoutCurrentColumn(data.Filter);
                //    filtered = false;
                //    //currentColumnFilter.Clear();
                //    return;
                //}

                // Declare a variable to store the filter string for this column.
                //List<String> newColumnFilter = new List<string>();

                // Store the column name in a form acceptable to the Filter property,
                // using a backslash to escape any closing square brackets.
                String columnProperty =
                    OwningColumn.DataPropertyName.Replace("]", @"\]");

                // Determine the column filter string based on the user selection.
                // For (Blanks) and (NonBlanks), the filter string determines whether
                // the column value is null or an empty string. Otherwise, the filter
                // string determines whether the column value is the selected value.
                //switch (selectedFilterValue)
                //{
                //    case "(Blanks)":
                //        newColumnFilter = String.Format(
                //            "LEN(ISNULL(CONVERT([{0}],'System.String'),''))=0",
                //            columnProperty);
                //        break;
                //    case "(NonBlanks)":
                //        newColumnFilter = String.Format(
                //            "LEN(ISNULL(CONVERT([{0}],'System.String'),''))>0",
                //            columnProperty);
                //        break;
                //    default:
                //newColumnFilter = String.Format("[{0}]='{1}'",
                //    columnProperty,
                //    ((String)filters[selectedFilterValue])
                //    .Replace("'", "''"));
                //        break;
                //}

                // Determine the new filter string by removing the previous column
                // filter string from the BindingSource.Filter value, then appending
                // the new column filter string, using " AND " as appropriate.
                //String newFilter = FilterWithoutCurrentColumn(data.Filter);
                //if (String.IsNullOrEmpty(newFilter))
                //{
                //    newFilter += newColumnFilter;
                //}
                //else
                //{
                //    newFilter += " AND " + newColumnFilter;
                //}


                // Set the filter to the new value.
                try
                {
                    //data.Filter = newFilter;
                }
                catch (InvalidExpressionException ex)
                {
                    //throw new NotSupportedException(
                    //"Invalid expression: " + newFilter, ex);
                }

                // Indicate that the column is currently filtered
                // and store the new column filter for use by subsequent
                // calls to the FilterWithoutCurrentColumn method.
                filtered = true;
                //currentColumnFilter = newColumnFilter;
            }
            else
            {
                StringBuilder filterString = new StringBuilder();

                switch (m_SelectedConstraintIndex)
                {
                case ConstraintValues.cv_filter_off:
                    // leave the string empty
                    filtered = false;
                    break;

                case ConstraintValues.cv_equals:
                    filterString.AppendFormat("({0} = {1})", this.OwningColumn.DataPropertyName, IBE.SQL.DBConnector.SQLAEscape(m_SelectedFilterText));
                    filtered = true;

                    break;

                case ConstraintValues.cv_contains:
                    filterString.AppendFormat("({0} like '%{1}%')", this.OwningColumn.DataPropertyName, IBE.SQL.DBConnector.SQLEscape(m_SelectedFilterText));
                    filtered = true;

                    break;

                case ConstraintValues.cv_starts_with:
                    filterString.AppendFormat("({0} like '{1}%')", this.OwningColumn.DataPropertyName, IBE.SQL.DBConnector.SQLEscape(m_SelectedFilterText));
                    filtered = true;

                    break;

                case ConstraintValues.cv_ends_with:
                    filterString.AppendFormat("({0} like '%{1}')", this.OwningColumn.DataPropertyName, IBE.SQL.DBConnector.SQLEscape(m_SelectedFilterText));
                    filtered = true;

                    break;
                }

                Retriever.SetFilter(this.OwningColumn.Name, filterString.ToString());
            }
        }
        /// <summary>
        /// Updates the BindingSource.Filter value based on a user selection
        /// from the drop-down filter list.
        /// </summary>
        override protected void UpdateFilter(Boolean onlyRefresh = false)
        {
            if (!onlyRefresh)
            {
                // Continue only if the selection has changed.
                if (filterWindow.FilterListBox.SelectedItem.ToString().Equals(selectedFilterValue))
                {
                    return;
                }

                // Store the new selection value.
                selectedFilterValue = filterWindow.FilterListBox.SelectedItem.ToString();
            }

            // Cast the data source to an IBindingListView.
            IBindingListView data =
                this.DataGridView.DataSource as IBindingListView;

            if ((data == null) && (Retriever == null))
            {
                return;
            }

            Debug.Assert((data != null && data.SupportsFiltering) || (Retriever != null),
                         "DataSource is not an IBindingListView or does not support filtering");

            if (data != null)
            {
                // If the user selection is (All), remove any filter currently
                // in effect for the column.
                if (selectedFilterValue.Equals("(All)"))
                {
                    data.Filter         = FilterWithoutCurrentColumn(data.Filter);
                    filtered            = false;
                    currentColumnFilter = String.Empty;
                    return;
                }

                // Declare a variable to store the filter string for this column.
                String newColumnFilter = null;

                // Store the column name in a form acceptable to the Filter property,
                // using a backslash to escape any closing square brackets.
                String columnProperty =
                    OwningColumn.DataPropertyName.Replace("]", @"\]");

                // Determine the column filter string based on the user selection.
                // For (Blanks) and (NonBlanks), the filter string determines whether
                // the column value is null or an empty string. Otherwise, the filter
                // string determines whether the column value is the selected value.
                switch (selectedFilterValue)
                {
                case "(Blanks)":
                    newColumnFilter = String.Format(
                        "LEN(ISNULL(CONVERT([{0}],'System.String'),''))=0",
                        columnProperty);
                    break;

                case "(NonBlanks)":
                    newColumnFilter = String.Format(
                        "LEN(ISNULL(CONVERT([{0}],'System.String'),''))>0",
                        columnProperty);
                    break;

                default:
                    newColumnFilter = String.Format("[{0}]='{1}'",
                                                    columnProperty,
                                                    ((String)filters[selectedFilterValue])
                                                    .Replace("'", "''"));
                    break;
                }

                // Determine the new filter string by removing the previous column
                // filter string from the BindingSource.Filter value, then appending
                // the new column filter string, using " AND " as appropriate.
                String newFilter = FilterWithoutCurrentColumn(data.Filter);
                if (String.IsNullOrEmpty(newFilter))
                {
                    newFilter += newColumnFilter;
                }
                else
                {
                    newFilter += " AND " + newColumnFilter;
                }


                // Set the filter to the new value.
                try
                {
                    data.Filter = newFilter;
                }
                catch (InvalidExpressionException ex)
                {
                    throw new NotSupportedException(
                              "Invalid expression: " + newFilter, ex);
                }

                // Indicate that the column is currently filtered
                // and store the new column filter for use by subsequent
                // calls to the FilterWithoutCurrentColumn method.
                filtered            = true;
                currentColumnFilter = newColumnFilter;
            }
            else
            {
                if (selectedFilterValue.Equals("(All)"))
                {
                    Retriever.SetFilter(this.OwningColumn.Name, "");
                    filtered = false;
                    return;
                }

                filtered = true;
                Retriever.SetFilter(this.OwningColumn.Name, String.Format("{0} = '{1}'", this.OwningColumn.DataPropertyName, selectedFilterValue));
            }
        }