public void FindNext() { if (_Viewer == null) { throw new ApplicationException("Viewer property must be set prior to issuing FindNext."); } if (tbFind.Text.Length == 0) // must have something to find { return; } RdlViewerFinds findOptions = ckMatchCase.Checked ? RdlViewerFinds.MatchCase : RdlViewerFinds.None; bool begin = position == null; position = _Viewer.Find(tbFind.Text, position, findOptions); if (position == null) { if (!begin) // if we didn't start from beginning already; try from beginning { position = _Viewer.Find(tbFind.Text, position, findOptions); } lStatus.Text = position == null ? "Phrase not found" : "Reached end of report, continued from top"; _Viewer.HighlightPageItem = position; if (position != null) { _Viewer.ScrollToPageItem(position); } } else { lStatus.Text = ""; _Viewer.HighlightPageItem = position; _Viewer.ScrollToPageItem(position); } }
public void FindNext() { if (_Viewer == null) { throw new ApplicationException(Strings.RdlViewerFind_ErrorA_PropertyMustSetPriorFindNext); } if (tbFind.Text.Length == 0) // must have something to find { return; } RdlViewerFinds findOptions = ckMatchCase.Checked ? RdlViewerFinds.MatchCase : RdlViewerFinds.None; bool begin = position == null; position = _Viewer.Find(tbFind.Text, position, findOptions); if (position == null) { if (!begin) // if we didn't start from beginning already; try from beginning { position = _Viewer.Find(tbFind.Text, position, findOptions); } lStatus.Text = position == null ? Strings.RdlViewerFind_FindNext_Phrase_not_found : Strings.RdlViewerFind_FindNext_Reached_end_of_report; _Viewer.HighlightPageItem = position; if (position != null) { _Viewer.ScrollToPageItem(position); } } else { lStatus.Text = ""; _Viewer.HighlightPageItem = position; _Viewer.ScrollToPageItem(position); } }
/// <summary> /// Find locates the next string after the passed location. Use ScrollToPageItem to then /// reposition the Viewer on that item /// </summary> /// <param name="search">Text to search for</param> /// <param name="position">PageItem after which to start search. null starts at beginning</param> /// <param name="options">Multiple options can be or'ed together.</param> /// <returns>null if not found</returns> public PageItem Find(string search, PageItem position, RdlViewerFinds options) { LoadPageIfNeeded(); if (_pgs == null || _pgs.Count == 0) // no report nothing to find return null; // initialize the loop direction and starting point int increment; int sPage; int sItem; if (((options & RdlViewerFinds.Backward) == RdlViewerFinds.Backward)) { // set to backward direction increment = -1; // go backwards sPage = _pgs.PageCount - 1; // start at last page sItem = _pgs[sPage].Count - 1; // start at bottom of last page } else { // set to forward direction increment = 1; sPage = 0; sItem = 0; } bool bFirst = true; if (position != null) { sPage = position.Page.PageNumber - 1; // start on same page as current sItem = position.ItemNumber + increment; // but on the item after/before the current one } if (!((options & RdlViewerFinds.MatchCase) == RdlViewerFinds.MatchCase)) search = search.ToLower(); // should use Culture!!! todo PageItem found = null; for (int pi = sPage; pi < _pgs.Count && found == null && pi >= 0; pi = pi + increment) { Page p = _pgs[pi]; if (bFirst) // The first time sItem is already set bFirst = false; else { if (increment < 0) // we're going backwards? sItem = p.Count - 1; // yes, start at bottom of page else sItem = 0; // no, start at top of page } for (int pii = sItem; pii < p.Count && found == null && pii >= 0; pii = pii + increment) { PageText pt = p[pii] as PageText; if (pt == null) continue; if ((options & RdlViewerFinds.MatchCase) == RdlViewerFinds.MatchCase) { if (pt.Text.Contains(search)) found = pt; } else { if (pt.Text.ToLower().Contains(search)) found = pt; } } } return found; }