예제 #1
0
        public void ShowDialog(string customerID, IWin32Window parent, IBindingListView blist)
        {
            // Put the customer id in the window title.
            this.Text = "Orders for Customer ID: " + customerID;

            dataGridView1.AutoGenerateColumns = false;
            dataGridView1.DataSource = blist;

            // The check box column will be virtual.
            dataGridView1.VirtualMode = true;
            dataGridView1.Columns.Insert(0, new DataGridViewCheckBoxColumn());

            // Don't allow the column to be resizable.
            dataGridView1.Columns[0].Resizable = DataGridViewTriState.False;

            // Make the check box column frozen so it is always visible.
            dataGridView1.Columns[0].Frozen = true;

            // Put an extra border to make the frozen column more visible
            dataGridView1.Columns[0].DividerWidth = 1;

            // Make all columns except the first read only.
            foreach (DataGridViewColumn c in dataGridView1.Columns)
                if (c.Index != 0) c.ReadOnly = true;

            // Initialize the dictionary that contains the boolean check state.
            checkState = new Dictionary<int, bool>();

            // Show the dialog.
            this.ShowDialog(parent);
        }
        public void ReadOnlyPropTest()
        {
            IBindingListView view = (IBindingListView) new DataView(table);

            Assert.IsTrue(view.SupportsAdvancedSorting, "#1");
            Assert.IsTrue(view.SupportsFiltering, "#2");
        }
예제 #3
0
        public void BaseSortWithInsertionAndFilter()
        {
            IBindingListView   sut = CreateBindingListOnBasicCustomersList();
            PropertyDescriptor pd  = TypeDescriptor.GetProperties(typeof(Customer)).Find("Name", false);

            sut.ApplySort(pd, ListSortDirection.Ascending);
            String lastName = "";

            foreach (Customer c in sut)
            {
                Assert.That(c.Name.CompareTo(lastName) > 0);
                lastName = c.Name;
            }
            sut.Filter = "Age > 30";
            sut.Add(new Customer()
            {
                Name = "Fernand", Age = 18
            });
            Assert.That(sut, Has.Count.EqualTo(3));
            lastName = "";
            foreach (Customer c in sut)
            {
                Assert.That(c.Name.CompareTo(lastName) > 0);
                lastName = c.Name;
            }
            sut.RemoveFilter();
            lastName = "";
            foreach (Customer c in sut)
            {
                Assert.That(c.Name.CompareTo(lastName) > 0);
                lastName = c.Name;
            }
        }
        public void SortDescriptionTest()
        {
            IBindingListView view = (IBindingListView) new DataView(table);

            ListSortDescriptionCollection col = view.SortDescriptions;

            ((DataView)view).Sort = "";
            col = view.SortDescriptions;
            Assert.AreEqual(0, col.Count, "#1");

            ((DataView)view).Sort = null;
            col = view.SortDescriptions;
            Assert.AreEqual(0, col.Count, "#2");

            ((DataView)view).Sort = "col1 DESC, col2 ASC";
            col = view.SortDescriptions;
            Assert.AreEqual(2, col.Count, "#3");
            Assert.AreEqual("col1", col[0].PropertyDescriptor.Name, "#4");
            Assert.AreEqual(ListSortDirection.Descending, col[0].SortDirection, "#5");
            Assert.AreEqual("col2", col[1].PropertyDescriptor.Name, "#6");
            Assert.AreEqual(ListSortDirection.Ascending, col[1].SortDirection, "#7");

            //ApplySort Test
            IBindingListView view1 = (IBindingListView) new DataView(table);

            Assert.IsFalse(view.Equals(view1), "#8");
            view1.ApplySort(col);
            Assert.AreEqual("[col1] DESC,[col2]", ((DataView)view1).Sort, "#9");
            for (int i = 0; i < view.Count; ++i)
            {
                Assert.AreEqual(((DataView)view)[i].Row, ((DataView)view1)[i].Row, "#10" + i);
            }
        }
예제 #5
0
 public void ApplyFilter(string expression)
 {
     if (this.sourceControl == null)
     {
         throw new NullReferenceException("The DataSource of the control is not set, which is required for the ApplyFilter method to execute.");
     }
     if (this.SourceControl is IBindingListView)
     {
         IBindingListView sourceControl = this.SourceControl as IBindingListView;
         if (string.IsNullOrEmpty(expression))
         {
             sourceControl.RemoveFilter();
         }
         else
         {
             sourceControl.Filter = expression;
         }
     }
     else if (this.SourceControl is DataView)
     {
         (this.SourceControl as DataView).RowFilter = expression;
     }
     else
     {
         if (!(this.SourceControl is DataTable))
         {
             throw new NotSupportedException(this.SourceControl.GetType().ToString() + " does not implement IBindingListView, which is required to apply the filter expression. The supported types are implementers of System.ComponentModel.IBindingListView, System.Data.DataTable and System.Data.DataView");
         }
         (this.SourceControl as DataTable).DefaultView.RowFilter = expression;
     }
 }
예제 #6
0
        public virtual void ApplySort(ListSortDescriptionCollection sorts)
        {
            if (!(list is IBindingListView))
            {
                throw new NotSupportedException("This operation requires an IBindingListView.");
            }

            IBindingListView iblist_view = (IBindingListView)list;

            iblist_view.ApplySort(sorts);
        }
예제 #7
0
        private void UpdateFilter()
        {
            if (!dropDownListBox.SelectedItem.ToString().Equals(this.selectedFilterValue))
            {
                this.selectedFilterValue = dropDownListBox.SelectedItem.ToString();
                IBindingListView dataSource = base.DataGridView.DataSource as IBindingListView;
                Debug.Assert((dataSource != null) && dataSource.SupportsFiltering, "DataSource is not an IBindingListView or does not support filtering");
                if (this.selectedFilterValue.Equals("(All)"))
                {
                    dataSource.Filter        = this.FilterWithoutCurrentColumn(dataSource.Filter);
                    this.filtered            = false;
                    this.currentColumnFilter = string.Empty;
                }
                else
                {
                    string str2 = null;
                    string str3 = base.OwningColumn.DataPropertyName.Replace("]", @"\]");
                    switch (this.selectedFilterValue)
                    {
                    case "(Blanks)":
                        str2 = string.Format("LEN(ISNULL(CONVERT([{0}],'System.String'),''))=0", str3);
                        break;

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

                    default:
                        str2 = string.Format("[{0}]='{1}'", str3, ((string)this.filters[this.selectedFilterValue]).Replace("'", "''"));
                        break;
                    }
                    string str = this.FilterWithoutCurrentColumn(dataSource.Filter);
                    if (string.IsNullOrEmpty(str))
                    {
                        str = str + str2;
                    }
                    else
                    {
                        str = str + " AND " + str2;
                    }
                    try
                    {
                        dataSource.Filter = str;
                    }
                    catch (InvalidExpressionException exception)
                    {
                        throw new NotSupportedException("Invalid expression: " + str, exception);
                    }
                    this.filtered            = true;
                    this.currentColumnFilter = str2;
                }
            }
        }
예제 #8
0
        public frmCustomFilter(string ColumnName,DataGridView dgView)
        {
            InitializeComponent();
            strColumnName = ColumnName;
            _dataGridView = dgView;

            // Cast the data source to an IBindingListView.
            data =_dataGridView.DataSource as IBindingListView;
            BindingSource s =(BindingSource)_dataGridView.DataSource;
            _dTable =(DataTable)s.DataSource;
            LoadComboBox();
        }
예제 #9
0
        private void ViewOrders(string customerID)
        {
            this.Cursor = Cursors.WaitCursor;

            // Show the CustomerOrders dialog, passing in the customer ID.
            CustomerOrdersForm co = new CustomerOrdersForm();

            // Get the related list of orders for the current customer.
            CurrencyManager  cm   = ((CurrencyManager)this.BindingContext[northwindDS, "Customers.CustOrders"]);
            IBindingListView list = (IBindingListView)cm.List;

            co.ShowDialog(customerID, this, list);

            this.Cursor = Cursors.Default;
        }
 protected override void InternalUpdateControlValueFromBo()
 {
     if (_businessObject != null)
     {
         var relationship = _businessObject.Relationships[PropertyName];
         var relatedObjectClassDef = relationship.RelatedObjectClassDef;
         var businessObjectCollection = _businessObject.Relationships.GetRelatedCollection(PropertyName);
         _bindingListView = CreateBindingListView(relatedObjectClassDef.ClassType, businessObjectCollection);
         _grid.DataSource = _bindingListView;
     }
     else
     {
         _grid.DataSource = null;
     }
 }
예제 #11
0
 protected override void InternalUpdateControlValueFromBo()
 {
     if (_businessObject != null)
     {
         var relationship             = _businessObject.Relationships[PropertyName];
         var relatedObjectClassDef    = relationship.RelatedObjectClassDef;
         var businessObjectCollection = _businessObject.Relationships.GetRelatedCollection(PropertyName);
         _bindingListView = CreateBindingListView(relatedObjectClassDef.ClassType, businessObjectCollection);
         _grid.DataSource = _bindingListView;
     }
     else
     {
         _grid.DataSource = null;
     }
 }
예제 #12
0
        protected void filter(IBindingListView source, StringSearchMatcher search)
        {
            if (propname == null || search.TextLength == 0)
            {
                source.RemoveFilter();
                if (propname == null) TextBox.Clear();
            }
            else
                source.Filter = propname + " like " + (AlwaysSearchInnerText ? "*" : null) + Text + "*";

            var p = GetCurrentPosition();
            if (p.X != pos.X && pos.X != -1 && RecordCount > 0 && p.Y != -1)
            {
                SetPosition(pos.X, p.Y);
            }
        }
예제 #13
0
        void sidePanel_FilterChanged(object sender, string text)
        {
            SidePanel panel = sender as SidePanel;

            if (panel != null)
            {
                IBindingListView view = null;
                if (this.viewState == ViewState.Events)
                {
                    view = this.rfidEventInfoBindingSource as IBindingListView;
                }
                else
                {
                    view = this.rnErrorEventArgsBindingSource as IBindingListView;
                }
                view.Filter = string.Format("{0} @ {1}%", panel.Filter, text);
            }
        }
예제 #14
0
        protected override IBindingListView GetBindingListView(IBusinessObjectCollection businessObjectCollection)
        {
            if (businessObjectCollection == null)
            {
                throw new ArgumentNullException("businessObjectCollection");
            }
            var classType = GetClassType(businessObjectCollection);

            if (this.ClassDef == null || this.ClassDef != businessObjectCollection.ClassDef)
            {
                this.ClassDef = businessObjectCollection.ClassDef;
            }
            _logger.Log("Start CreateBindingListView : classType : " + classType, LogCategory.Debug);
            _logger.Log(GetStackTrace(), LogCategory.Debug);

            //Needs this code
            //            var uiDef = ((ClassDef) this.ClassDef).GetUIDef(UiDefName);
//            if (uiDef == null)
//            {
//                throw new ArgumentException
//                    (String.Format
//                         ("You cannot Get the data for the grid {0} since the uiDef {1} cannot be found for the classDef {2}",
//                          this._gridBase.Name, UiDefName, ((ClassDef)this.ClassDef).ClassName));
//            }
            IViewBuilder viewBuilder = null;

            try
            {
                Type defaultViewBuilderType = typeof(DefaultViewBuilder <>).MakeGenericType(classType);
                viewBuilder = (IViewBuilder)Activator.CreateInstance(defaultViewBuilderType);
            }
            catch (Exception e)
            {
                _logger.Log(e.Message, LogCategory.Exception);
                Console.WriteLine(e);
            }

            var bindingListType = typeof(BindingListView <>).MakeGenericType(classType);

            _bindingListView =
                (IBindingListView)Activator.CreateInstance(bindingListType, businessObjectCollection, viewBuilder);
            return(_bindingListView);
        }
        public void FilterTest()
        {
            IBindingListView view = (IBindingListView) new DataView(table);

            view.Filter = "";
            Assert.AreEqual(table.Rows.Count, view.Count, "#1");

            view.Filter = null;
            Assert.AreEqual(table.Rows.Count, view.Count, "#2");

            view.Filter = "col1 <> 1";
            Assert.AreEqual(view.Filter, ((DataView)view).RowFilter, "#4");
            Assert.AreEqual(6, view.Count, "#5");

            //RemoveFilter Test
            view.RemoveFilter();
            Assert.AreEqual("", view.Filter, "#6");
            Assert.AreEqual("", ((DataView)view).RowFilter, "#7");
            Assert.AreEqual(table.Rows.Count, view.Count, "#8");
        }
예제 #16
0
        public void BaseSort()
        {
            IBindingListView   sut = CreateBindingListOnBasicCustomersList();
            PropertyDescriptor pd  = TypeDescriptor.GetProperties(typeof(Customer)).Find("Name", false);

            sut.ApplySort(pd, ListSortDirection.Ascending);
            String lastName = "";

            foreach (Customer c in sut)
            {
                Assert.That(c.Name.CompareTo(lastName) > 0);
                lastName = c.Name;
            }
            sut.ApplySort(pd, ListSortDirection.Descending);
            lastName = "ZZZZZZZZZZZZZZZ";
            foreach (Customer c in sut)
            {
                Assert.That(lastName.CompareTo(c.Name) > 0);
                lastName = c.Name;
            }
        }
        protected override IBindingListView GetBindingListView(IBusinessObjectCollection businessObjectCollection)
        {
            if (businessObjectCollection == null) throw new ArgumentNullException("businessObjectCollection");
            var classType = GetClassType(businessObjectCollection);
            if (this.ClassDef == null || this.ClassDef != businessObjectCollection.ClassDef)
            {
                this.ClassDef = businessObjectCollection.ClassDef;
            }
            _logger.Log("Start CreateBindingListView : classType : " + classType, LogCategory.Debug);
            _logger.Log(GetStackTrace(), LogCategory.Debug);

            //Needs this code 
            //            var uiDef = ((ClassDef) this.ClassDef).GetUIDef(UiDefName);
//            if (uiDef == null)
//            {
//                throw new ArgumentException
//                    (String.Format
//                         ("You cannot Get the data for the grid {0} since the uiDef {1} cannot be found for the classDef {2}",
//                          this._gridBase.Name, UiDefName, ((ClassDef)this.ClassDef).ClassName));
//            }
            IViewBuilder viewBuilder = null;
            try
            {
                Type defaultViewBuilderType = typeof (DefaultViewBuilder<>).MakeGenericType(classType);
                viewBuilder = (IViewBuilder) Activator.CreateInstance(defaultViewBuilderType);
            }
            catch (Exception e)
            {
                _logger.Log(e.Message, LogCategory.Exception);
                Console.WriteLine(e);
            }

            var bindingListType = typeof (BindingListView<>).MakeGenericType(classType);
            _bindingListView =
                (IBindingListView) Activator.CreateInstance(bindingListType, businessObjectCollection, viewBuilder);
            return _bindingListView;
        }
예제 #18
0
        public void ShowDialog(string customerID, IWin32Window parent, IBindingListView blist)
        {
            // Put the customer id in the window title.
            this.Text = "Orders for Customer ID: " + customerID;

            dataGridView1.AutoGenerateColumns = false;
            dataGridView1.DataSource          = blist;

            // The check box column will be virtual.
            dataGridView1.VirtualMode = true;
            dataGridView1.Columns.Insert(0, new DataGridViewCheckBoxColumn());

            // Don't allow the column to be resizable.
            dataGridView1.Columns[0].Resizable = DataGridViewTriState.False;

            // Make the check box column frozen so it is always visible.
            dataGridView1.Columns[0].Frozen = true;

            // Put an extra border to make the frozen column more visible
            dataGridView1.Columns[0].DividerWidth = 1;

            // Make all columns except the first read only.
            foreach (DataGridViewColumn c in dataGridView1.Columns)
            {
                if (c.Index != 0)
                {
                    c.ReadOnly = true;
                }
            }

            // Initialize the dictionary that contains the boolean check state.
            checkState = new Dictionary <int, bool>();

            // Show the dialog.
            this.ShowDialog(parent);
        }
        ///// <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());
            }
        }
예제 #20
0
 public BindingListView(IBindingListView source, Func <PropertyDescriptor, PropertyDescriptor> propertyMapper) : base(source, propertyMapper)
 {
     this.source = source;
 }
        internal LikeLookUpEditDataProvider(IBindingListView BindingListView, XOFieldContext FieldContext)
        {
            _bindingListView = BindingListView;

            _fieldContex = FieldContext;
        }
            public zz(DataView x)
            {
                this.x = x;

            }
        /// <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));
            }
        }
예제 #24
0
 void BindingListView_CustomSort(int iColumn)
 {
     if (DataSource != null && iColumn >= 0 && iColumn < this.Columns.Count)
     {
         ColumnBinding header = this.Columns[iColumn] as ColumnBinding;
         if (header != null)
         {
             IBindingListView view = this.DataSource as IBindingListView;
             if (view != null)
             {
                 string fieldName = header.Property != null ? header.Property.Name : header.FieldName;
                 if (!string.IsNullOrEmpty(fieldName))
                 {
                     // handle existing sorts
                     if (view.IsSorted)
                     {
                         ListSortDescription[] arr = new ListSortDescription[view.SortDescriptions.Count];
                         view.SortDescriptions.CopyTo(arr, 0);
                         bool found = false;
                         for (int idx = 0; idx < arr.Length; ++idx)
                         {
                             ListSortDescription desc = arr[idx];
                             if (desc.PropertyDescriptor.Name == fieldName)
                             {
                                 found = true;
                                 if (idx == 0)
                                 {
                                     if (desc.SortDirection == ListSortDirection.Descending)
                                     {
                                         desc.SortDirection = ListSortDirection.Ascending;
                                     }
                                     else
                                     {
                                         List <ListSortDescription> list = new List <ListSortDescription>(arr);
                                         list.Remove(desc);
                                         arr = list.ToArray();
                                     }
                                 }
                                 else
                                 {
                                     List <ListSortDescription> list = new List <ListSortDescription>(arr);
                                     list.Remove(desc);
                                     list.Insert(0, desc);
                                     desc.SortDirection = ListSortDirection.Ascending;
                                     arr = list.ToArray();
                                 }
                                 break;
                             }
                         }
                         if (!found)
                         {
                             List <ListSortDescription> list = new List <ListSortDescription>(arr);
                             list.Insert(0, new ListSortDescription(header.Property, ListSortDirection.Descending));
                             while (list.Count > 3)
                             {
                                 list.RemoveAt(list.Count - 1);
                             }
                             arr = list.ToArray();
                         }
                         view.ApplySort(new ListSortDescriptionCollection(arr));
                     }
                     else
                     {
                         view.ApplySort(header.Property, ListSortDirection.Ascending);
                     }
                 }
             }
         }
     }
 }