Beispiel #1
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;
            }
        }
Beispiel #2
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;
     }
 }
Beispiel #3
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);
            }
        }
        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");
        }
Beispiel #5
0
 public void RemoveFilter()
 {
     source.RemoveFilter();
 }