Ejemplo n.º 1
0
        void findAndReplaceDialog_FindNextEvent(object sender, EventArgs e)
        {
            if (searchIterator == null ||
                currentSearchText != findAndReplaceDialog.GetSearchText() ||
                currentComparisonOperation != findAndReplaceDialog.GetComparisonOperation())
            {
                searchIterator             = new FindPreprocessingItemsIterator(FindAll(findAndReplaceDialog.GetSearchText()));
                currentSearchText          = findAndReplaceDialog.GetSearchText();
                currentComparisonOperation = findAndReplaceDialog.GetComparisonOperation();
            }

            if (IsOneCellSelected())
            {
                var first = GetSelectedCells().First();
                searchIterator.SetStartCell(first.Key, first.Value[0]);
            }

            bool moreOccurences = false;

            currentCell    = searchIterator.GetCurrent();
            moreOccurences = searchIterator.MoveNext();
            if (IsOneCellSelected() && currentCell != null)
            {
                var first = GetSelectedCells().First();
                if (currentCell.Item1 == first.Key && currentCell.Item2 == first.Value[0])
                {
                    if (!moreOccurences)
                    {
                        searchIterator.Reset();
                    }
                    currentCell    = searchIterator.GetCurrent();
                    moreOccurences = searchIterator.MoveNext();
                    if (!moreOccurences)
                    {
                        searchIterator.Reset();
                    }
                }
            }

            dataGridView.ClearSelection();

            if (currentCell != null)
            {
                dataGridView[currentCell.Item1, currentCell.Item2].Selected = true;
                dataGridView.CurrentCell = dataGridView[currentCell.Item1, currentCell.Item2];
            }
        }