Ejemplo n.º 1
0
        private void toolFilterBox_TextChanged(object sender, EventArgs e)
        {
            if (itemListViewExt.Columns.Count < 4)
            {
                return;
            }

            TextMatchFilter filter = null;

            filter = TextMatchFilter.Contains(itemListViewExt, toolFilterBox.Text);

            if (filter == null)
            {
                itemListViewExt.DefaultRenderer = null;
            }
            else
            {
                itemListViewExt.DefaultRenderer = new HighlightTextRenderer(filter);
            }

            // Some lists have renderers already installed
            HighlightTextRenderer highlightingRenderer = itemListViewExt.GetColumn(3).Renderer as HighlightTextRenderer;

            if (highlightingRenderer != null)
            {
                highlightingRenderer.Filter = filter;
            }

            //Stopwatch stopWatch = new Stopwatch();
            //stopWatch.Start();
            itemListViewExt.AdditionalFilter = filter;
            //olv.Invalidate();
            //stopWatch.Stop();
        }
Ejemplo n.º 2
0
        // Search by text, expanding any parent nodes to reveal child match.
        internal void AddStringFilter(String text)
        {
            // If string filter is not null, try and remove it from active filter list
            if (StringFilter != null)
            {
                if (this.Filters.Contains(StringFilter))
                {
                    this.Filters.Remove(StringFilter);
                }
                StringFilter = null;
            }

            // Only search if string is not empty, and ensure all matched children are showing by expanding parents.
            if (!String.IsNullOrEmpty(text))
            {
                StringFilter         = TextMatchFilter.Contains(this.ListView, text);
                StringFilter.Columns = new OLVColumn[] { ListView.NlmColumns.NameColumn };
                ExpandParentsOfMatchedChildren(text);
                this.Filters.Add(StringFilter);
            }

            // Set the filter to correspone to the text being searched. If text is "", nothing is filtered.
            HighlightTextRenderer highLightingRenderer = ListView.NlmColumns.NameColumn.Renderer as HighlightTextRenderer;

            if (highLightingRenderer != null)
            {
                highLightingRenderer.Filter = StringFilter;
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 过滤表格
        /// </summary>
        /// <param name="view">表格对象</param>
        /// <param name="key">查询关键字</param>
        public static void Filter(ObjectListView view, string key)
        {
            TextMatchFilter filter = null;

            if (key.Length > 0)
            {
                filter = TextMatchFilter.Contains(view, key);
            }
            if (filter == null)
            {
                view.DefaultRenderer = null;
            }
            else
            {
                view.DefaultRenderer = new HighlightTextRenderer(filter);
            }
            HighlightTextRenderer highlightingRenderer = view.GetColumn(0).Renderer as HighlightTextRenderer;

            if (highlightingRenderer != null)
            {
                highlightingRenderer.Filter = filter;
            }

            view.ModelFilter = filter;
        }
Ejemplo n.º 4
0
        public static void FilterFOLV(FastObjectListView OLV, string FilterText, bool Filter)
        {
            using var cw = new Global_GUI.CursorWait();

            try
            {
                if (!string.IsNullOrEmpty(FilterText))
                {
                    if (Filter)
                    {
                        OLV.UseFiltering = true;
                    }
                    else
                    {
                        OLV.UseFiltering = false;
                    }
                    TextMatchFilter filter = TextMatchFilter.Regex(OLV, FilterText);
                    OLV.ModelFilter = filter;
                    HighlightTextRenderer renderererer = new HighlightTextRenderer(filter);
                    SolidBrush            brush        = renderererer.FillBrush as SolidBrush ?? new SolidBrush(Color.Transparent);
                    brush.Color            = System.Drawing.Color.FromArgb(100, Color.LightSeaGreen); //
                    renderererer.FillBrush = brush;
                    OLV.DefaultRenderer    = renderererer;
                    Global.SaveRegSetting("SearchText", FilterText);
                }
                else
                {
                    OLV.ModelFilter = null;
                }
                OLV.Refresh();
                //Application.DoEvents();
            }
            catch { }
        }
Ejemplo n.º 5
0
        public static void DoListViewFilter(ObjectListView olv, String txtInput)
        {
            try
            {
                TextMatchFilter filter = null;
                if (!String.IsNullOrEmpty(txtInput.Trim()))
                {
                    filter = new TextMatchFilter(olv, txtInput, StringComparison.CurrentCultureIgnoreCase);
                }
                // Setup a default renderer to draw the filter matches
                if (filter == null)
                {
                    olv.DefaultRenderer = null;
                }
                else
                {
                    olv.DefaultRenderer = new HighlightTextRenderer(filter);
                }
                // Some lists have renderers already installed
                HighlightTextRenderer highlightingRenderer = olv.GetColumn(0).Renderer as HighlightTextRenderer;
                if (highlightingRenderer != null)
                {
                    highlightingRenderer.Filter = filter;
                }

                olv.ModelFilter = filter;
            }
            catch { }
        }
        void TimedFilter(ObjectListView olv, string txt, int matchKind)
        {
            TextMatchFilter filter = null;

            if (!String.IsNullOrEmpty(txt))
            {
                switch (matchKind)
                {
                case 0:
                default:
                    filter = TextMatchFilter.Contains(olv, txt);
                    break;

                case 1:
                    filter = TextMatchFilter.Prefix(olv, txt);
                    break;

                case 2:
                    filter = TextMatchFilter.Regex(olv, txt);
                    break;
                }
            }
            if (filter == null)
            {
                olv.DefaultRenderer = null;
            }
            else
            {
                olv.DefaultRenderer = new HighlightTextRenderer(filter);
            }

            HighlightTextRenderer highlightingRenderer = olv.GetColumn(0).Renderer as HighlightTextRenderer;

            if (highlightingRenderer != null)
            {
                highlightingRenderer.Filter = filter;
            }

            Stopwatch stopWatch = new Stopwatch();

            stopWatch.Start();
            olv.ModelFilter = filter;
            stopWatch.Stop();

            IList objects = olv.Objects as IList;

            if (objects == null)
            {
                this.toolStripStatusLabel1.Text =
                    String.Format("Filtered in {0}ms", stopWatch.ElapsedMilliseconds);
            }
            else
            {
                this.toolStripStatusLabel1.Text =
                    String.Format("Filtered {0} items down to {1} items in {2}ms",
                                  objects.Count,
                                  olv.Items.Count,
                                  stopWatch.ElapsedMilliseconds);
            }
        }
Ejemplo n.º 7
0
        private void objectLstVwLatestBet_SelectionChanged(object sender, EventArgs e)
        {
            if (this.objectLstVwLatestBet.SelectedObjects.Count <= 0)
            {
                return;
            }
            LotteryBet      lotteryBet = (LotteryBet)objectLstVwLatestBet.SelectedObjects[0];
            TextMatchFilter filter     = new TextMatchFilter(this.objectLstVwLatestBet);

            List <String> regex = new List <string>();

            foreach (int n in lotteryBet.GetAllNumberSequenceSorted())
            {
                regex.Add("^" + n.ToString() + "$");
            }
            filter.RegexStrings = regex;

            HighlightTextRenderer highlightTextRenderer = new HighlightTextRenderer(filter);

            highlightTextRenderer.CornerRoundness       = 1;
            highlightTextRenderer.FramePen              = new Pen(Color.Empty);
            highlightTextRenderer.FillBrush             = new SolidBrush(Color.LightBlue);
            highlightTextRenderer.CellPadding           = new Rectangle(0, 0, 0, 0);
            highlightTextRenderer.Bounds                = new Rectangle(2, 2, 2, 2);
            this.objectLstVwLatestBet.ModelFilter       = filter;
            this.objectLstVwLatestBet.DefaultRenderer   = highlightTextRenderer;
            this.objectLstVwLatestBet.SelectedForeColor = Color.Black;
            this.objectLstVwLatestBet.Refresh();
        }
Ejemplo n.º 8
0
        void Filter(FastObjectListView olv, string txt, int matchKind)
        {
            olv.OwnerDraw = true;
            TextMatchFilter filter = null;

            if (!String.IsNullOrEmpty(txt))
            {
                switch (matchKind)
                {
                case 0:
                default:
                    filter = TextMatchFilter.Contains(olv, txt);
                    break;

                case 1:
                    filter = TextMatchFilter.Prefix(olv, txt);
                    break;

                case 2:
                    filter = TextMatchFilter.Regex(olv, txt);
                    break;
                }
            }
            // Setup a default renderer to draw the filter matches
            if (filter == null)
            {
                olv.DefaultRenderer = null;
                olv.ModelFilter     = null;
            }
            else
            {
                olv.DefaultRenderer = new HighlightTextRenderer(filter);
                olv.ModelFilter     = filter;
                // Uncomment this line to see how the GDI+ rendering looks
                //olv.DefaultRenderer = new HighlightTextRenderer { Filter = filter, UseGdiTextRendering = false };
            }

            // Some lists have renderers already installed
            HighlightTextRenderer highlightingRenderer = olv.GetColumn(0).Renderer as HighlightTextRenderer;

            if (highlightingRenderer != null)
            {
                highlightingRenderer.Filter = filter;
            }

            IList objects = olv.Objects as IList;

            if ((objects == null) || (objects.Count == olv.Items.Count))
            {
                this.toolStripStatusLabel1.Text = string.Empty;
            }
            else
            {
                this.toolStripStatusLabel1.Text =
                    String.Format("Filtered {0} items down to {1} items",
                                  objects.Count,
                                  olv.Items.Count);
            }
        }
Ejemplo n.º 9
0
 private void SearchTextChanged(object sender, EventArgs e)
 {
     filter  = TextMatchFilter.Contains(modListView, textBoxSearch.Text);
     hfilter = new HighlightTextRenderer(filter);
     modListView.ModelFilter     = filter;
     modListView.DefaultRenderer = hfilter;
     hfilter.UseRoundedRectangle = false;
 }
Ejemplo n.º 10
0
 private void TextBox_Search_TextChanged(object sender, EventArgs e)
 {
     filter  = TextMatchFilter.Contains(olvLootList, textBoxSearch.Text);
     hfilter = new HighlightTextRenderer(filter);
     olvLootList.ModelFilter     = filter;
     olvLootList.DefaultRenderer = hfilter;
     hfilter.UseRoundedRectangle = false;
     Olv_ParseEntries();
 }
Ejemplo n.º 11
0
        private void FilterList(ObjectListView olv, string searchText, bool showMatching = false)
        {
            // Construct the regex to search for
            string[]      SearchedString = searchText.Split('*');
            StringBuilder regex          = new StringBuilder();

            //regex.Append(".*");

            foreach (string term in SearchedString)
            {
                if (term != string.Empty && Array.IndexOf(SearchedString, term) == (SearchedString.Length - 1))
                {
                    regex.Append(term);
                }
                else
                {
                    regex.Append(term + ".*");
                }
            }
            regex.Append(".*");
            System.Text.RegularExpressions.Regex r = new System.Text.RegularExpressions.Regex("^" + regex.ToString() + "$", System.Text.RegularExpressions.RegexOptions.IgnoreCase & System.Text.RegularExpressions.RegexOptions.Multiline);

            TextMatchFilter filter = null;

            if (!string.IsNullOrEmpty(searchText))
            {
                filter = TextMatchFilter.Regex(olv, r.ToString());
            }

            if (showMatching)
            {
                // Setup a default renderer to draw the filter matches
                if (filter == null)
                {
                    olv.DefaultRenderer = null;
                }
                else
                {
                    olv.DefaultRenderer = new HighlightTextRenderer(filter);
                }

                // Some lists have renderers already installed
                HighlightTextRenderer highlightingRenderer = olv.GetColumn(0).Renderer as HighlightTextRenderer;
                if (highlightingRenderer != null)
                {
                    highlightingRenderer.Filter = filter;
                }

                olv.AdditionalFilter = filter;
            }
            else
            {
                olv.DefaultRenderer  = null;
                olv.AdditionalFilter = filter;
            }
        }
Ejemplo n.º 12
0
        void TimedFilter(ObjectListView olv, string txt, int matchKind)
        {
            TextMatchFilter filter = null;

            if (!String.IsNullOrEmpty(txt))
            {
                switch (matchKind)
                {
                case 0:
                default:
                    filter = TextMatchFilter.Contains(olv, txt);
                    break;

                case 1:
                    filter = TextMatchFilter.Prefix(olv, txt);
                    break;

                case 2:
                    filter = TextMatchFilter.Regex(olv, txt);
                    break;
                }
            }
            // Setup a default renderer to draw the filter matches
            olv.DefaultRenderer = filter == null ? null : new HighlightTextRenderer(filter);
            // Some lists have renderers already installed
            HighlightTextRenderer highlightingRenderer = olv.GetColumn(0).Renderer as HighlightTextRenderer;

            if (highlightingRenderer != null)
            {
                highlightingRenderer.Filter = filter;
            }

            Stopwatch stopWatch = new Stopwatch();

            stopWatch.Start();
            olv.AdditionalFilter = filter;
            //olv.Invalidate();
            stopWatch.Stop();

            IList objects = olv.Objects as IList;

            if (objects == null)
            {
                toolStripStatusLabel1.Text =
                    String.Format("Filtered in {0}ms", stopWatch.ElapsedMilliseconds);
            }
            else
            {
                toolStripStatusLabel1.Text =
                    String.Format("在 {0} 条数据中过滤出符合条件的 {1} 数据,耗时{2}ms",
                                  objects.Count,
                                  olv.Items.Count,
                                  stopWatch.ElapsedMilliseconds);
            }
        }
Ejemplo n.º 13
0
        /// <summary>
        /// This will remove the list filter.
        /// </summary>
        public void RemoveStringFilter()
        {
            TextMatchFilter tmfFilter = TextMatchFilter.Contains(this, String.Empty);

            tmfFilter.Columns = new OLVColumn[] { (OLVColumn)this.Columns[0] };
            HighlightTextRenderer highlightingRenderer = this.GetColumn(0).Renderer as HighlightTextRenderer;

            if (highlightingRenderer != null)
            {
                highlightingRenderer.Filter = tmfFilter;
            }
            m_strLastSearchFilter = String.Empty;
        }
Ejemplo n.º 14
0
        /// <summary>
        /// This will apply a string filter to the list.
        /// </summary>
        /// /// <param name="p_strFilter">The string filter.</param>
        public void AddStringFilter(string p_strFilter)
        {
            TextMatchFilter tmfFilter = TextMatchFilter.Contains(this, p_strFilter);

            tmfFilter.Columns = new OLVColumn[] { (OLVColumn)this.Columns[0] };
            this.ModelFilter  = tmfFilter;
            HighlightTextRenderer highlightingRenderer = this.GetColumn(0).Renderer as HighlightTextRenderer;

            if (highlightingRenderer != null)
            {
                highlightingRenderer.Filter = tmfFilter;
            }
            m_strLastSearchFilter = p_strFilter;
        }
        private void objListVwBet_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (this.objListVwBet.SelectedObjects.Count <= 0)
            {
                return;
            }
            LotteryBet      lotteryBet = (LotteryBet)objListVwBet.SelectedObjects[0];
            TextMatchFilter filter     = new TextMatchFilter(this.objListVwDrawResult);

            List <String> regex = new List <string>();

            foreach (int n in lotteryBet.GetAllNumberSequenceSorted())
            {
                regex.Add("^" + n.ToString() + "$");
            }
            filter.RegexStrings = regex;

            HighlightTextRenderer highlightTextRenderer = new HighlightTextRenderer(filter);

            highlightTextRenderer.CornerRoundness      = 1;
            highlightTextRenderer.FramePen             = new Pen(Color.Empty);
            highlightTextRenderer.FillBrush            = new SolidBrush(Color.LightBlue);
            highlightTextRenderer.CellPadding          = new Rectangle(0, 0, 0, 0);
            highlightTextRenderer.Bounds               = new Rectangle(2, 2, 2, 2);
            this.objListVwDrawResult.ModelFilter       = filter;
            this.objListVwDrawResult.DefaultRenderer   = highlightTextRenderer;
            this.objListVwDrawResult.SelectedForeColor = Color.Black;

            int itemProcessCtr = 0;

            toolStripProgBarRefresh.Value   = 0;
            toolStripProgBarRefresh.Visible = true;
            toolStripStatusLbl.Visible      = true;
            this.objListVwDrawResult.BeginUpdate();
            foreach (OLVListItem item in this.objListVwDrawResult.Items)
            {
                toolStripProgBarRefresh.Value = ConverterUtils.GetPercentageFloored(++itemProcessCtr, this.objListVwDrawResult.Items.Count);
                this.objListVwDrawResult.RefreshObject(item.RowObject);
                if (itemProcessCtr % 50 == 0)
                {
                    Application.DoEvents();
                }
            }

            this.objListVwDrawResult.EndUpdate();
            this.objListVwDrawResult.Sort();
            toolStripProgBarRefresh.Value   = 0;
            toolStripProgBarRefresh.Visible = false;
            toolStripStatusLbl.Visible      = false;
        }
Ejemplo n.º 16
0
        public static void OLVFilter(ObjectListView olv, string txt, int matchKind)
        {
            TextMatchFilter filter = null;

            if (!String.IsNullOrEmpty(txt))
            {
                switch (matchKind)
                {
                case 0:
                default:
                    filter = TextMatchFilter.Contains(olv, txt);
                    break;

                case 1:
                    filter = TextMatchFilter.Prefix(olv, txt);
                    break;

                case 2:
                    filter = TextMatchFilter.Regex(olv, txt);
                    break;
                }
            }
            // Setup a default renderer to draw the filter matches

            if (filter == null)
            {
                olv.DefaultRenderer = null;
            }
            else
            {
                olv.DefaultRenderer = new HighlightTextRenderer(filter);

                // Uncomment this line to see how the GDI+ rendering looks
                //olv.DefaultRenderer = new HighlightTextRenderer { Filter = filter, UseGdiTextRendering = false };
            }

            // Some lists have renderers already installed
            HighlightTextRenderer highlightingRenderer = olv.GetColumn(0).Renderer as HighlightTextRenderer;

            if (highlightingRenderer != null)
            {
                highlightingRenderer.Filter = filter;
            }


            olv.AdditionalFilter = filter;
            //olv.Invalidate();
        }
Ejemplo n.º 17
0
        public static void ApplyFilters(ObjectListView olv, string[] filterTexts, int matchKind)
        {
            TextMatchFilter     textMatchFilter = null;//Using this textMatchFilter for hightlight purpose
            List <IModelFilter> modelFilters    = null;

            if (filterTexts != null && filterTexts.Length > 0)
            {
                textMatchFilter = OLVHelpers.createTextMatchFilter(olv, filterTexts, matchKind);

                modelFilters = new List <IModelFilter>();
                foreach (string s in filterTexts)
                {
                    modelFilters.Add(OLVHelpers.createTextMatchFilter(olv, new string[] { s }, matchKind));
                }
            }

            // Setup a default renderer to draw the filter matches
            if (textMatchFilter == null)
            {
                olv.DefaultRenderer = null;
            }
            else
            {
                olv.DefaultRenderer = new HighlightTextRenderer(textMatchFilter);

                // Uncomment this line to see how the GDI+ rendering looks
                //olv.DefaultRenderer = new HighlightTextRenderer { Filter = filter, UseGdiTextRendering = false };
            }

            // Some lists have renderers already installed
            HighlightTextRenderer highlightingRenderer = olv.GetColumn(0).Renderer as HighlightTextRenderer;

            if (highlightingRenderer != null)
            {
                highlightingRenderer.Filter = textMatchFilter;
            }


            olv.ModelFilter = modelFilters == null ? null : new CompositeAllFilter(modelFilters); //WHEN USING CompositeAllFilter, this textMatchFilter for HIGHTLIGHT PURPOSE ONLY
            //olv.AdditionalFilter = textMatchFilter; //WHEN USING AdditionalFilter: In addition to use this textMatchFilter for hightlight purpose, this textMatchFilter CAN BE USE FOR AdditionalFilter TO FILLER
            //NOTE:     AdditionalFilter: TO FILTER rows where any cell match any of the given strings array (string[]) --- MEANING: USING 'OR' CLAUSE
            //          ModelFilter with CompositeAllFilter: CREATE SEPARATE textMatchFilter FOR EVERY item IN strings array (string[]), THEN COMBINE ALL FILTER TOGETHER --- MEANING: USING 'AND' CLAUSE
            //ONLY USING AdditionalFilter OR CompositeAllFilter AT ONE TIME

            //olv.Invalidate();
        }
Ejemplo n.º 18
0
        private void TimedFilter(ObjectListView folv, string txt, int matchKind)
        {
            TextMatchFilter filter = null;

            if (!String.IsNullOrEmpty(txt))
            {
                switch (matchKind)
                {
                case 0:
                default:
                    filter = TextMatchFilter.Prefix(folv, txt);
                    break;

                case 1:
                    filter = TextMatchFilter.Contains(folv, txt);
                    break;

                case 2:
                    filter = TextMatchFilter.Regex(folv, txt);
                    break;
                }
            }
            // Setup a default renderer to draw the filter matches
            if (filter == null)
            {
                folv.DefaultRenderer = null;
            }
            else
            {
                folv.DefaultRenderer = new HighlightTextRenderer(filter);
            }

            // Some lists have renderers already installed
            HighlightTextRenderer highlightingRenderer = folv.GetColumn(0).Renderer as HighlightTextRenderer;

            if (highlightingRenderer != null)
            {
                highlightingRenderer.Filter = filter;
            }

            Stopwatch stopWatch = new Stopwatch();

            stopWatch.Start();
            folv.ModelFilter = filter;
            stopWatch.Stop();
        }
Ejemplo n.º 19
0
        public void TimeFilter(String aFilterStr, FilterType aType)
        {
            TextMatchFilter nFilter = null;

            if (!String.IsNullOrEmpty(aFilterStr))
            {
                switch (aType)
                {
                default:
                case FilterType.CONTAINS:
                    nFilter = TextMatchFilter.Contains(this, aFilterStr);
                    break;

                case FilterType.PREFIX:
                    nFilter = TextMatchFilter.Prefix(this, aFilterStr);
                    break;

                case FilterType.REGEX:
                    nFilter = TextMatchFilter.Regex(this, aFilterStr);
                    break;
                }
            }

            if (nFilter == null)
            {
                this.DefaultRenderer = null;
            }
            else
            {
                this.DefaultRenderer = new HighlightTextRenderer(nFilter);
            }

            // Some lists have renderers already installed
            HighlightTextRenderer highlightingRenderer = this.GetColumn(0).Renderer as HighlightTextRenderer;

            if (highlightingRenderer != null)
            {
                highlightingRenderer.Filter = nFilter;
            }

            this.AdditionalFilter = nFilter;
        }
Ejemplo n.º 20
0
        void TimedFilter(ObjectListView olv, string txt)
        {
            TextMatchFilter filter = null;

            if (!String.IsNullOrEmpty(txt))
            {
                filter = TextMatchFilter.Contains(olv, txt);
            }
            // Setup a default renderer to draw the filter matches
            if (filter == null)
            {
                olv.DefaultRenderer = null;
            }
            else
            {
                HighlightTextRenderer htr = new HighlightTextRenderer(filter);
                htr.FillBrush       = Brushes.AliceBlue;
                olv.DefaultRenderer = htr; //new HighlightTextRenderer(filter);

                // Uncomment this line to see how the GDI+ rendering looks
                //olv.DefaultRenderer = new HighlightTextRenderer { Filter = filter, UseGdiTextRendering = false };
            }

            // Some lists have renderers already installed
            HighlightTextRenderer highlightingRenderer = olv.GetColumn(0).Renderer as HighlightTextRenderer;

            if (highlightingRenderer != null)
            {
                highlightingRenderer.Filter = filter;
            }

            CompositeAllFilter currentFilter = null;

            if (filter != null)
            {
                // Get the existing model filters, if any, remove any existing TextMatchFilters,
                // then add the new TextMatchFilter
                if (olv.ModelFilter == null)  // easy, just add the new one
                {
                    List <IModelFilter> listOfFilters = new List <IModelFilter>();
                    listOfFilters.Add(filter);  //add the TextMatchFilter
                    CompositeAllFilter compositeFilter = new CompositeAllFilter(listOfFilters);
                    olv.ModelFilter = compositeFilter;
                }
                else  //need to remove existing TextMatchFilters, if any, than add the new one
                {
                    currentFilter = (CompositeAllFilter)olv.ModelFilter;
                    //find the first existing TextMatchFilter (should be at most one) and remove it
                    foreach (IModelFilter m in currentFilter.Filters)
                    {
                        if (m is TextMatchFilter)
                        {
                            currentFilter.Filters.Remove(m);
                            break;
                        }
                    }

                    //add the new TextMatchFilter
                    if (olv.ModelFilter != null)
                    {
                        (olv.ModelFilter as CompositeAllFilter).Filters.Add(filter);
                    }
                    else
                    {
                        List <IModelFilter> listOfFilters = new List <IModelFilter>();
                        listOfFilters.Add(filter);  //add the TextMatchFilter
                        CompositeAllFilter compositeFilter = new CompositeAllFilter(listOfFilters);
                        olv.ModelFilter = compositeFilter;
                    }
                }
            }
            else //remove text filter
            {
                if (olv.ModelFilter != null)
                {
                    currentFilter = (CompositeAllFilter)olv.ModelFilter;
                    //find and remove the first existing TextMatchFilter if any
                    foreach (IModelFilter m in currentFilter.Filters)
                    {
                        if (m is TextMatchFilter)
                        {
                            currentFilter.Filters.Remove(m);
                            break;
                        }
                    }
                    if (currentFilter.Filters.Count == 0)
                    {
                        fastDataListView1.ModelFilter = null;
                    }
                }
            }

            if (currentFilter != null)
            {
                fastDataListView1.ModelFilter = currentFilter;
            }

            updateStatusLine(fastDataListView1);
        }
Ejemplo n.º 21
0
        private void materialSingleLineTextField3_TextChanged(object sender, EventArgs e)
        {
            string txt = materialSingleLineTextField3.Text;
            //Debug.WriteLine("过滤: " + txt);
            int             matchKind = comboBox4.SelectedIndex;
            TextMatchFilter filter    = null;

            if (!String.IsNullOrEmpty(txt))
            {
                switch (matchKind)
                {
                case 0:
                default:
                    filter = TextMatchFilter.Contains(fastObjectListView1, txt);
                    break;

                case 1:
                    filter = TextMatchFilter.Prefix(fastObjectListView1, txt);
                    break;

                case 2:
                    filter = TextMatchFilter.Regex(fastObjectListView1, txt);
                    break;
                }
            }

            if (filter == null)
            {
                fastObjectListView1.DefaultRenderer = null;
            }
            else
            {
                fastObjectListView1.DefaultRenderer = new HighlightTextRenderer(filter);

                // 可以选择GDI渲染高亮
                //fastObjectListView1.DefaultRenderer = new HighlightTextRenderer { Filter = filter, UseGdiTextRendering = false };
            }

            // 如果使用了其他过滤器
            HighlightTextRenderer highlightingRenderer = fastObjectListView1.GetColumn(0).Renderer as HighlightTextRenderer;

            if (highlightingRenderer != null)
            {
                highlightingRenderer.Filter = filter;
            }

            Stopwatch stopWatch = new Stopwatch();

            stopWatch.Start();
            fastObjectListView1.AdditionalFilter = filter;
            stopWatch.Stop();

            IList objects = fastObjectListView1.Objects as IList;

            if (objects == null)
            {
                SetTips(String.Format("过滤完成, 消耗 {0} 毫秒", stopWatch.ElapsedMilliseconds));
            }
            else
            {
                SetTips(String.Format("过滤完成, 总元素数量 {0} , 过滤后元素数量 {1} ,消耗 {2} 毫秒",
                                      objects.Count,
                                      fastObjectListView1.Items.Count,
                                      stopWatch.ElapsedMilliseconds));
            }

            fastObjectListView1.Invalidate();

            //Debug.WriteLine("过滤: " + txt + " 完毕.");
        }
        void TimedFilter(ObjectListView olv, string txt, int matchKind)
        {
            TextMatchFilter filter = null;

            if (!String.IsNullOrEmpty(txt))
            {
                switch (matchKind)
                {
                case 0:
                default:
                    filter = TextMatchFilter.Contains(olv, txt);
                    break;

                case 1:
                    filter = TextMatchFilter.Prefix(olv, txt);
                    break;

                case 2:
                    filter = TextMatchFilter.Regex(olv, txt);
                    break;
                }
            }
            // Setup a default renderer to draw the filter matches
            if (filter == null)
            {
                olv.DefaultRenderer = null;
            }
            else
            {
                olv.DefaultRenderer = new HighlightTextRenderer(filter);
                // Uncomment this line to see how the GDI+ rendering looks
                //olv.DefaultRenderer = new HighlightTextRenderer { Filter = filter, UseGdiTextRendering = false };
            }

            // Some lists have renderers already installed
            HighlightTextRenderer highlightingRenderer = olv.GetColumn(0).Renderer as HighlightTextRenderer;

            if (highlightingRenderer != null)
            {
                highlightingRenderer.Filter = filter;
            }
            Stopwatch stopWatch = new Stopwatch();

            stopWatch.Start();
            olv.AdditionalFilter = filter;
            olv.Invalidate();
            stopWatch.Stop();

            IList objects = olv.Objects as IList;

            if (objects == null)
            {
                string msg = String.Format("Filtered in {0}ms", stopWatch.ElapsedMilliseconds);
                this.toolTip1.SetToolTip(this.textBoxFilterTree, msg);
            }
            else
            {
                string msg = String.Format("Filtered {0} items down to {1} items in {2}ms",
                                           objects.Count,
                                           olv.Items.Count,
                                           stopWatch.ElapsedMilliseconds);
                this.toolTip1.SetToolTip(this.textBoxFilterTree, msg);
            }
        }