Пример #1
0
        public void TestSearchForVirtualItemEventArgs()
        {
            SearchDirectionHint sdh = SearchDirectionHint.Right;
            bool   includesubitems  = true;
            int    index            = 84;
            bool   isprefix         = true;
            bool   istext           = false;
            int    start            = 34;
            Point  startpoint       = new Point(64, 35);
            string text             = "HiThere!";

            SearchForVirtualItemEventArgs e = new SearchForVirtualItemEventArgs(istext, isprefix, includesubitems, text, startpoint, sdh, start);

            Assert.AreEqual(sdh, e.Direction, "A1");
            Assert.AreEqual(includesubitems, e.IncludeSubItemsInSearch, "A2");
            Assert.AreEqual(-1, e.Index, "A3");
            Assert.AreEqual(isprefix, e.IsPrefixSearch, "A4");
            Assert.AreEqual(istext, e.IsTextSearch, "A5");
            Assert.AreEqual(start, e.StartIndex, "A6");
            Assert.AreEqual(startpoint, e.StartingPoint, "A7");
            Assert.AreEqual(text, e.Text, "A8");

            e.Index = index;
            Assert.AreEqual(index, e.Index, "A9");
        }
Пример #2
0
        private void _list_SearchForVirtualItem(object sender, SearchForVirtualItemEventArgs e)
        {
            var comparisonType = ignoreCase
                                    ? StringComparison.InvariantCultureIgnoreCase
                                    : StringComparison.InvariantCulture;

            if (searchUp)
            {
                for (var i = SelectedIndex - 1; i >= 0; --i)
                {
                    var op = packets[i].Code.ToString();
                    if (op.IndexOf(e.Text, comparisonType) != -1)
                    {
                        e.Index = i;
                        break;
                    }
                }
            }
            else
            {
                for (int i = SelectedIndex + 1; i < _list.Items.Count; ++i)
                {
                    var op = packets[i].Code.ToString();
                    if (op.IndexOf(e.Text, comparisonType) != -1)
                    {
                        e.Index = i;
                        break;
                    }
                }
            }
        }
Пример #3
0
        private void ItemsListView_SearchForVirtualItem(object sender, SearchForVirtualItemEventArgs e)
        {
            int index = 0;

            if (sortAlphabetically)
            {
                List <object> items = new List <object>();
                items.AddRange(itemsSortedAlphabetically);
                index = FindMyStringInList(items, searchVal, searchIndex);
            }
            else
            {
                index = FindMyStringInList((sourcesLbx.SelectedItem as DataSource).Items, searchVal, searchIndex);
            }

            // find the item if index >= 0
            if (index >= 0)
            {
                e.Index = index;
            }
            else
            {
                if (searchIndex > 0)
                {
                    e.Index = searchIndex - 1;
                    MessageBox.Show("Reached the starting point of the seach.");
                    searchIndex = 0;
                    searchTbx.Focus();
                    return;
                }
                System.Media.SystemSounds.Hand.Play();
                MessageBox.Show("No items were found for that search", "Warning");
            }
        }
Пример #4
0
        private void _list_SearchForVirtualItem(object sender, SearchForVirtualItemEventArgs e)
        {
            var comparisonType = _ignoreCase
                                    ? StringComparison.InvariantCultureIgnoreCase
                                    : StringComparison.InvariantCulture;

            if (_searchUp)
            {
                for (var i = SelectedIndex - 1; i >= 0; --i)
                {
                    if (SearchMatches(e, comparisonType, i))
                    {
                        break;
                    }
                }
            }
            else
            {
                for (int i = SelectedIndex + 1; i < PacketView.Items.Count; ++i)
                {
                    if (SearchMatches(e, comparisonType, i))
                    {
                        break;
                    }
                }
            }
        }
Пример #5
0
        void ifListView_SearchForVirtualItem(object sender, SearchForVirtualItemEventArgs e)
        {
            if (_searchList == null)
            {
                ListViewBinding binding = _bindings.OfType <SubItemBinding>().First(b => b.SubItemIndex == 0);

                if (binding != null)
                {
                    _searchList = new Dictionary <string, int>();

                    int index = 0;
                    foreach (object obj in _dataSource)
                    {
                        string value = binding.GetValue(obj).ToString();

                        _searchList[value] = index;

                        index++;
                    }
                }
            }

            if (_searchList != null)
            {
                string key = _searchList.Keys.FirstOrDefault(k => k.StartsWith(e.Text, StringComparison.OrdinalIgnoreCase));

                if (key != null)
                {
                    e.Index = _searchList[key];
                }
            }
        }
Пример #6
0
        public void Search(NoFlickerListView fileList, SearchForVirtualItemEventArgs e)
        {
            bool ignoreCase    = true;
            bool searchUp      = false;
            int  SelectedIndex = fileList.SelectedIndex;

            var comparisonType = ignoreCase
                                    ? StringComparison.InvariantCultureIgnoreCase
                                    : StringComparison.InvariantCulture;

            if (searchUp)
            {
                for (var i = SelectedIndex - 1; i >= 0; --i)
                {
                    var op = _displayedEntries[i].Name;
                    if (op.IndexOf(e.Text, comparisonType) != -1)
                    {
                        e.Index = i;
                        break;
                    }
                }
            }
            else
            {
                for (int i = SelectedIndex + 1; i < fileList.Items.Count; ++i)
                {
                    var op = _displayedEntries[i].Name;
                    if (op.IndexOf(e.Text, comparisonType) != -1)
                    {
                        e.Index = i;
                        break;
                    }
                }
            }
        }
Пример #7
0
 /// <summary>
 /// Raises the <see cref="E:System.Windows.Forms.ListView.SearchForVirtualItem" /> event.
 /// </summary>
 /// <param name="e">A <see cref="T:System.Windows.Forms.SearchForVirtualItemEventArgs" /> that contains the event data.</param>
 protected override void OnSearchForVirtualItem(SearchForVirtualItemEventArgs e)
 {
     if (dataManager != null)
     {
         IBindingList bl = dataManager.List as IBindingList;
         if (bl != null && bl.SupportsSearching)
         {
             if (!e.IncludeSubItemsInSearch)
             {
                 e.Index = bl.Find(dataSourceProperties[0], e.Text);
             }
             else
             {
                 int idx;
                 for (int i = 0; i < dataSourceProperties.Count; i++)
                 {
                     idx = bl.Find(dataSourceProperties[i], e.Text);
                     if (idx != -1)
                     {
                         e.Index = idx;
                         break;
                     }
                 }
             }
         }
     }
     base.OnSearchForVirtualItem(e);
 }
Пример #8
0
        private void Browser_SearchForVirtualItem(object sender, SearchForVirtualItemEventArgs e)
        {
            var y = m_ShellItemInfo.Skip(e.StartIndex).Where(x => x.Name.StartsWith(e.Text, StringComparison.OrdinalIgnoreCase)).ToArray();

            if (y.Length > 0)
            {
                e.Index = m_ShellItemInfo.IndexOf(y[0]);
            }
        }
        public void Index_Set_GetReturnsExpected(int value)
        {
            var e = new SearchForVirtualItemEventArgs(false, true, false, "text", new Point(1, 2), SearchDirectionHint.Down, 1)
            {
                Index = value
            };

            Assert.Equal(value, e.Index);
        }
Пример #10
0
        /// <summary>
        /// Handle the SearchForVirtualList event, which is called when the user types into a virtual list
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void HandleSearchForVirtualItem(object sender, SearchForVirtualItemEventArgs e)
        {
            // We can't do anything if we don't have a data source
            if (this.DataSource == null)
            {
                return;
            }

            // We also can't do anything if we don't have data
            if (this.DataSource.GetObjectCount() == 0)
            {
                return;
            }

            // The event has e.IsPrefixSearch, but as far as I can tell, this is always false (maybe that's different under Vista)
            // So we ignore IsPrefixSearch and IsTextSearch and always to a case insensitve prefix match
            OLVColumn column = this.GetColumn(0);

            if (this.IsSearchOnSortColumn && this.View == View.Details && this.LastSortColumn != null)
            {
                column = this.LastSortColumn;
            }

            // Where should we start searching? If the last row is focused, the SearchForVirtualItemEvent starts searching
            // from the next row, which is actually an invalidate index -- in that case, we rewind one row to the last row.
            int start = e.StartIndex;

            if (e.StartIndex == this.DataSource.GetObjectCount())
            {
                start--;
            }

            // Do two searches if necessary to find a match. The second search is the wrap-around part of searching
            int i;

            if (e.Direction == SearchDirectionHint.Down)
            {
                i = this.DataSource.SearchText(e.Text, start, this.DataSource.GetObjectCount() - 1, column);
                if (i == -1 && e.StartIndex > 0)
                {
                    i = this.DataSource.SearchText(e.Text, 0, start - 1, column);
                }
            }
            else
            {
                i = this.DataSource.SearchText(e.Text, start, 0, column);
                if (i == -1 && e.StartIndex != this.DataSource.GetObjectCount())
                {
                    i = this.DataSource.SearchText(e.Text, this.DataSource.GetObjectCount() - 1, start + 1, column);
                }
            }
            if (i != -1)
            {
                e.Index = i;
            }
        }
Пример #11
0
        private void lvFamily_SearchForVirtualItem(object sender, SearchForVirtualItemEventArgs e)
        {
            //e.IncludeSubItemsInSearch = true;
            var results = families.Where(o => o.Text.StartsWith(e.Text, StringComparison.CurrentCultureIgnoreCase));

            if (results.Count() > 0)
            {
                e.Index = results.First().Index;
            }
        }
Пример #12
0
        private bool SearchForVirtualItem(int n, SearchForVirtualItemEventArgs e)
        {
            if (_filteredList[n].ToString().ToUpper().StartsWith(e.Text.ToUpper()))
            {
                e.Index = n;
                return(true);
            }

            return(false);
        }
Пример #13
0
 private void listView1_SearchForVirtualItem(object sender, SearchForVirtualItemEventArgs e)
 {
     for (int i = 0; i < _listItems.Count; i++)
     {
         var item = _listItems[i];
         if (item.AssemblyName.Contains(e.Text))
         {
             e.Index = i;
         }
     }
 }
Пример #14
0
 // ------------------------------------------------------------------------
 // This event handler enables search functionality, and is called
 // for every search request when in Virtual mode.
 // ------------------------------------------------------------------------
 void this_SearchForVirtualItem(object sender, SearchForVirtualItemEventArgs e)
 {
     for (int pos = 0; pos < _list.Count; ++pos)
     {
         if (_list[pos].fileName.StartsWith(e.Text, StringComparison.OrdinalIgnoreCase))
         {
             e.Index = pos;
             break;
         }
     }
 }
Пример #15
0
        private bool SearchMatches(SearchForVirtualItemEventArgs e, StringComparison comparisonType, int i)
        {
            var op = packets[i].Code.ToString();

            if (op.IndexOf(e.Text, comparisonType) != -1)
            {
                e.Index = i;
                return(true);
            }
            return(false);
        }
Пример #16
0
 private void lstLabels_SearchForVirtualItem(object sender, SearchForVirtualItemEventArgs e)
 {
     for (int i = 0; i < _listItems.Count; i++)
     {
         if (_listItems[i].Text.StartsWith(e.Text, StringComparison.InvariantCultureIgnoreCase))
         {
             e.Index = i;
             return;
         }
     }
 }
Пример #17
0
        void tileViewControl1_SearchItem(object sender, SearchForVirtualItemEventArgs e)
        {
            int res;

            if (int.TryParse(e.Text, out res))
            {
                if (res < tileViewControl1.VirtualListSize)
                {
                    e.Index = res;
                }
            }
        }
Пример #18
0
 private void OOC_Logs_ListView_SearchForVirtualItem(object sender, SearchForVirtualItemEventArgs e)
 {
     for (int i = 0; i < OOC_Logs_ListView.Items.Count; i++)
     {
         if (Regex.IsMatch(i.ToString(), e.ToString()))
         {
             OOC_Logs_ListView.Items[i].Selected = true;
             OOC_Logs_ListView.Items[i].Checked  = true;
             MessageBox.Show(OOC_Logs_ListView.Items[i].ToString());
         }
     }
 }
        public void Ctor_Bool_Bool_Bool_String_Point_SearchDirectionHint_Int(bool isTextSearch, bool isPrefixSearch, bool includeSubItemsInSearch, string text, Point startingPoint, SearchDirectionHint direction, int startIndex)
        {
            var e = new SearchForVirtualItemEventArgs(isTextSearch, isPrefixSearch, includeSubItemsInSearch, text, startingPoint, direction, startIndex);

            Assert.Equal(isTextSearch, e.IsTextSearch);
            Assert.Equal(isPrefixSearch, e.IsPrefixSearch);
            Assert.Equal(includeSubItemsInSearch, e.IncludeSubItemsInSearch);
            Assert.Equal(text, e.Text);
            Assert.Equal(startingPoint, e.StartingPoint);
            Assert.Equal(direction, e.Direction);
            Assert.Equal(startIndex, e.StartIndex);
            Assert.Equal(-1, e.Index);
        }
        private void OnGameListViewSearchForVirtualItem(object sender, SearchForVirtualItemEventArgs e)
        {
            if (e.Direction != SearchDirectionHint.Down || e.IsTextSearch == false)
            {
                return;
            }

            var count = this._FilteredGames.Count;

            if (count < 2)
            {
                return;
            }

            var text       = e.Text;
            int startIndex = e.StartIndex;

            Predicate <GameInfo> predicate;
            /*if (e.IsPrefixSearch == true)*/
            {
                predicate = gi => gi.Name != null && gi.Name.StartsWith(text, StringComparison.CurrentCultureIgnoreCase);
            }

            /*else
             * {
             *  predicate = gi => gi.Name != null && string.Compare(gi.Name, text, StringComparison.CurrentCultureIgnoreCase) == 0;
             * }*/

            int index;

            if (e.StartIndex >= count)
            {
                // starting from the last item in the list
                index = this._FilteredGames.FindIndex(0, startIndex - 1, predicate);
            }
            else if (startIndex <= 0)
            {
                // starting from the first item in the list
                index = this._FilteredGames.FindIndex(0, count, predicate);
            }
            else
            {
                index = this._FilteredGames.FindIndex(startIndex, count - startIndex, predicate);
                if (index < 0)
                {
                    index = this._FilteredGames.FindIndex(0, startIndex - 1, predicate);
                }
            }

            e.Index = index < 0 ? -1 : index;
        }
Пример #21
0
        private void ViewerListView_SearchForVirtualItem(object sender, SearchForVirtualItemEventArgs e)
        {
            //We've gotten a search request.
            //In this example, finding the item is easy since it's
            //just the square of its index.  We'll take the square root
            //and round.
            int b = Array.FindIndex(dbData.viewerList, n => n.name.Contains(e.Text));

            if (b >= 0)
            {
                e.Index = b;
            }
            //If e.Index is not set, the search returns null.
            //Note that this only handles simple searches over the entire
            //list, ignoring any other settings.  Handling Direction, StartIndex,
            //and the other propertwaies of SearchForVirtualItemEventArgs is up
            //to this handler.
        }
Пример #22
0
        private void ListView_SearchForVirtualItem(object sender, SearchForVirtualItemEventArgs e)
        {
            for (int n = e.StartIndex + 1; n < _filteredList.Count; ++n)
            {
                if (SearchForVirtualItem(n, e))
                {
                    return;
                }
            }

            for (int n = 0; n < e.StartIndex; ++n)
            {
                if (SearchForVirtualItem(n, e))
                {
                    return;
                }
            }
        }
Пример #23
0
 protected virtual void HandleSearchForVirtualItem(object sender, SearchForVirtualItemEventArgs e)
 {
     if (this.DataSource != null)
     {
         int startSearchFrom           = Math.Min(e.StartIndex, this.DataSource.GetObjectCount() - 1);
         BeforeSearchingEventArgs args = new BeforeSearchingEventArgs(e.Text, startSearchFrom);
         this.OnBeforeSearching(args);
         if (!args.Canceled)
         {
             int indexSelected             = this.FindMatchingRow(args.StringToFind, args.StartSearchFrom, e.Direction);
             AfterSearchingEventArgs args2 = new AfterSearchingEventArgs(args.StringToFind, indexSelected);
             this.OnAfterSearching(args2);
             if (indexSelected != -1)
             {
                 e.Index = indexSelected;
             }
         }
     }
 }
Пример #24
0
 private void lstGames_SearchForVirtualItem(object sender, SearchForVirtualItemEventArgs e)
 {
     for (int i = e.StartIndex; i < displayedGames.Count; i++)
     {
         if (displayedGames[i].Name.StartsWith(e.Text, StringComparison.CurrentCultureIgnoreCase))
         {
             e.Index = i;
             return;
         }
     }
     for (int i = 0; i < e.StartIndex; i++)
     {
         if (displayedGames[i].Name.StartsWith(e.Text, StringComparison.CurrentCultureIgnoreCase))
         {
             e.Index = i;
             return;
         }
     }
 }
Пример #25
0
    //</snippet3>

    //<snippet4>
    //This event handler enables search functionality, and is called
    //for every search request when in Virtual mode.
    void listView1_SearchForVirtualItem(object sender, SearchForVirtualItemEventArgs e)
    {
        //We've gotten a search request.
        //In this example, finding the item is easy since it's
        //just the square of its index.  We'll take the square root
        //and round.
        double x = 0;

        if (Double.TryParse(e.Text, out x)) //check if this is a valid search
        {
            x       = Math.Sqrt(x);
            x       = Math.Round(x);
            e.Index = (int)x;
        }
        //If e.Index is not set, the search returns null.
        //Note that this only handles simple searches over the entire
        //list, ignoring any other settings.  Handling Direction, StartIndex,
        //and the other properties of SearchForVirtualItemEventArgs is up
        //to this handler.
    }
Пример #26
0
        void FastObjectListView_SearchForVirtualItem(object sender, SearchForVirtualItemEventArgs e)
        {
            // The event has e.IsPrefixSearch, but as far as I can tell, this is always false (maybe that's different under Vista)
            // So we ignore IsPrefixSearch and IsTextSearch and always to a case insensitve prefix match

            int       increment = (e.Direction == SearchDirectionHint.Up ? -1 : 1);
            OLVColumn column    = this.GetColumn(0);

            if (this.IsSearchOnSortColumn && this.View == View.Details && this.lastSortColumn != null)
            {
                column = this.lastSortColumn;
            }

            int i;

            for (i = e.StartIndex; i >= 0 && i < this.objectList.Count; i += increment)
            {
                string data = column.GetStringValue(this.objectList[i]);
                if (data.StartsWith(e.Text, StringComparison.CurrentCultureIgnoreCase))
                {
                    e.Index = i;
                    return;
                }
            }

            // Also the LVFINDINFO has a LV_WRAP flag, but the SearchForVirtualItemEventArgs does not. Why?
            // We always wrap
            i = (increment < 0 ? this.objectList.Count : 0);
            while ((increment < 0 && i > e.StartIndex) || (increment > 0 && i < e.StartIndex))
            {
                string data = column.GetStringValue(this.objectList[i]);
                if (data.StartsWith(e.Text, StringComparison.CurrentCultureIgnoreCase))
                {
                    e.Index = i;
                    return;
                }
                i += increment;
            }
        }
Пример #27
0
        /// <summary>
        /// Handle the SearchForVirtualList event, which is called when the user types into a virtual list
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected virtual void HandleSearchForVirtualItem(object sender, SearchForVirtualItemEventArgs e)
        {
            // The event has e.IsPrefixSearch, but as far as I can tell, this is always false (maybe that's different under Vista)
            // So we ignore IsPrefixSearch and IsTextSearch and always to a case insensitve prefix match.

            // We can't do anything if we don't have a data source
            if (this.DataSource == null)
            {
                return;
            }

            // Where should we start searching? If the last row is focused, the SearchForVirtualItemEvent starts searching
            // from the next row, which is actually an invalidate index -- so we make sure we never go past the last object.
            int start = Math.Min(e.StartIndex, this.DataSource.GetObjectCount() - 1);

            // Give the world a chance to fiddle with or completely avoid the searching process
            BeforeSearchingEventArgs args = new BeforeSearchingEventArgs(e.Text, start);

            this.OnBeforeSearching(args);
            if (args.Canceled)
            {
                return;
            }

            // Do the search
            int i = this.FindMatchingRow(args.StringToFind, args.StartSearchFrom, e.Direction);

            // Tell the world that a search has occurred
            AfterSearchingEventArgs args2 = new AfterSearchingEventArgs(args.StringToFind, i);

            this.OnAfterSearching(args2);

            // If we found a match, tell the event
            if (i != -1)
            {
                e.Index = i;
            }
        }
Пример #28
0
 private void fileList_SearchForVirtualItem(object sender, SearchForVirtualItemEventArgs e)
 {
     viewHelper.Search(fileList, e);
 }
Пример #29
0
 private void listViewmonan_SearchForVirtualItem(object sender, SearchForVirtualItemEventArgs e)
 {
     //listViewmonan.FindItemWithText(tbxtensanpham.Text, true, 0);
 }
Пример #30
0
        /// <summary>Handles the SearchForVirtualItem event of the listView control.</summary>
        /// <remarks>This will be used for keyboard search, which is an important UI feature.</remarks>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.Forms.SearchForVirtualItemEventArgs"/> instance containing the event data.</param>
        private void listView_SearchForVirtualItem(object sender, SearchForVirtualItemEventArgs e)
        {
            // Note 1: The IsPrefix property of SearchForVirtualItemEventArgs seems to be false for keyboard prefix search events…
            // Since this is the only use we'll have of this method, we can assume this is always a prefix search.
            // Note 2: We'll assume that we are always searching forward. (This is important for "proximity" search)

            if (rootNode == null)
            {
                return;
            }

            // Since we are processing filenames, the invariant culture will be used here.
            var nodes = rootNode.Nodes;
            // Assuming the nodes re sorted alphabetically (they should be !), the binary search is the most efficient choice.
            int prefixLength = e.Text.Length;
            int low, high;             // These will represent the dynamic search range.
            int difference;

            // Match the prefix against the start item.
            difference = string.Compare(nodes[e.StartIndex].Text, 0, e.Text, 0, prefixLength, StringComparison.OrdinalIgnoreCase);

            // Depending on the prefix comparison, we can either adjust search parameters or even terminate the search. ;)
            if (difference == 0)
            {
                // If the test is successful, then the start item was the item we were looking for !
                e.Index = e.StartIndex;
                return;
            }
            else if (difference > 0)
            {
                // If prefix may only be found before the start item, search before
                low = 0;
                if (e.StartIndex > 0)
                {
                    high = e.StartIndex - 1;
                }
                else
                {
                    return;                  // If start item was the first item, then the search failed.
                }
            }
            else
            {
                // If prefix may only be found after the start item, search after
                if (e.StartIndex + 1 < nodes.Count)
                {
                    low = e.StartIndex + 1;
                }
                else
                {
                    return;                  // If start item was the last item, then the search failed.
                }
                high = nodes.Count - 1;
            }

            // In this algorithm, we may have low == high, but this is a normal (final) case.
            do
            {
                int    pivot = (low + high) / 2;
                string text  = nodes[pivot].Text;

                difference = string.Compare(text, 0, e.Text, 0, Math.Min(prefixLength, text.Length), StringComparison.OrdinalIgnoreCase);

                if (difference == 0)
                {
                    // Once a match is found, adjust the search parameters accordingly
                    high = (e.Index = pivot) - 1;
                    if (text.Length == prefixLength)
                    {
                        return;                                                  // If the full string was matched by the "prefix", we have our final result
                    }
                }
                else if (difference > 0)
                {
                    if ((high = pivot - 1) < 0)
                    {
                        return;
                    }
                }
                else if ((low = pivot + 1) == nodes.Count)
                {
                    return;
                }
            } while (low <= high);
        }