Skip to main content
A newer version of this page is available. .
.NET Framework 4.5.2+

ISearchResult Interface

Defines the interface used for text searching.

Namespace: DevExpress.XtraRichEdit.API.Native

Assembly: DevExpress.RichEdit.v19.1.Core.dll

Declaration

[ComVisible(true)]
public interface ISearchResult

Remarks

The SubDocument.StartSearch method provides the ISearchResult interface. You can then start searching, or make replacements.

The following code demonstrates how to create the ISearchResult interface, and use it to perform a search. The search interface is created for a case sensitive search, matching only whole words, i.e. strings delimited with characters which are not alphabetical or decimal digits.

The SearchStringIsEmpty() function is a custom function that checks the search text and returns true if the search string is empty.

If the search direction is SearchDirection.Forward, the search starts from the end of the current selection and proceeds forward to the end of the document. The ISearchResult.FindNext method is called to perform a search. When a matching text is found, it is selected and the document is scrolled to make the selection visible. The range containing the matched string can be obtained via the ISearchResult.CurrentResult property.

using DevExpress.XtraRichEdit;
using DevExpress.XtraRichEdit.API.Native;
        ISearchResult searchResult;
        Document Document { get { return this.richEditControl1.Document; } }
        SearchDirection direction = SearchDirection.Forward;
        SearchOptions options = SearchOptions.WholeWord |
            SearchOptions.CaseSensitive;

        ISearchResult SearchResult {
            get {
                if (searchResult == null)
                    searchResult = CreateSearchResult();
                return searchResult;
            }
        }
        private ISearchResult CreateSearchResult() {
            DocumentRange range;
            if (direction == SearchDirection.Forward) {
                int startPos = Document.Selection.End.ToInt();
                int length = Document.Range.End.ToInt() - startPos;
                range = Document.CreateRange(startPos, length);
            }
            else {
                int length = Document.Selection.Start.ToInt();
                range = Document.CreateRange(0, length);
            }
            return Document.StartSearch(searchString, options, direction, range);
        }
        private bool FindNext() {
            if(SearchStringIsEmpty())
                return false;
            if(SearchResult.FindNext()) {
                Document.Selection = SearchResult.CurrentResult;
                this.richEditControl1.ScrollToCaret();
                return true;
            }
            else {
                XtraMessageBox.Show("Search is complete.", Application.ProductName);
                return false;
            }
        }

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the ISearchResult interface.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also