SearchControl Class

A search control.

Namespace: DevExpress.Xpf.Editors

Assembly: DevExpress.Xpf.Core.v20.2.dll

Declaration

public class SearchControl :
    Control
Public Class SearchControl
    Inherits Control

The following members accept/return SearchControl objects:

Remarks

The Search Control provides an easy way for end users to locate information within data editors (list boxes, combo boxes, etc). To execute a search, enter the text in the search box. Data editors bound to the Search Control will display those records that have matching values.

Various options are available to control the display and behavior of the Search Control. You can specify search columns, choose between automatic and manual search modes, optionally display control buttons, etc.

Search Syntax

  • Single keyword.

    Sales - Selects records that contain the "Sales" string in any search column.

  • To search for a string that contains a space character, specify this string in quotation marks.

    "Sales Manager" - Selects records that contain "Sales Manager" in any search column.

  • Without quotation marks, words separated by the space character are treated as individual conditions.

    Sales Manager - Selects records that contain either "Sales" or "Manager" strings in any search column.

  • To search against a specific column, precede a search string with the column's display name plus a colon character.

    TIP

    Instead of the complete name, you can partially specify the display name using the initial characters of a column's display name. A search is performed against the first column whose display name starts with the specified substring.

    To search against a column whose display caption contains space characters, specify the column's display caption in quotation marks.

    Group:Sales - Selects records that contain "Sales" in the column that starts with "Group".

    NOTE

    If the search string contains multiple conditions separated by space characters, and at least one condition defines a search against a specific column, only records that match all of these conditions are shown (i.e., the conditions are combined by the And logical operator).

    If there is no column specification, records that match at least one of these conditions are shown (i.e., the conditions are combined by the Or logical operator).

    Group:Sales Manager - Selects records that contain "Sales" in the column that starts with "Group", and also contain "Manager" in any search column.

  • Precede a condition with "+" to display only records that match this condition. The "+" specifier allows you to implement the logical And operator. There should be no space character between the "+" sign and the condition.

    Sales +Specialist - Selects records that contain both "Sales" and "Specialist" in search columns.

  • Precede a condition with "-" to exclude records that match this condition from the result set. There should be no space between the "-" sign and the condition.

    Sales -Specialist - Selects records that contain "Sales" excluding records that contain "Specialist".

    NOTE

    If the expression contains the "-" character, quotation marks are ignored.

  • You can combine different operators.

    Sales +Representative -"United States" - Selects records that contain both "Sales" and "Representative" in search columns, excluding records that contain "United States".

Examples

This example shows how to use the SearchControl to locate required items displayed within a list box. To execute a search, enter a text within the Find box, and the list box linked to the Search Control will display those records that have matching values.

View Example

<Window x:Class="ListBoxFilteringUsingSearchPanel.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525"
        xmlns:sys="clr-namespace:System;assembly=mscorlib"
        xmlns:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition/>
            <RowDefinition/>
        </Grid.RowDefinitions>
        <dxe:SearchControl x:Name="searchControl" Grid.Row="0" Margin="10"
                           HorizontalAlignment="Stretch" VerticalAlignment="Center"
                           FilterCondition="Contains"
                           FilterByColumnsMode="Custom"
                           >
            <dxe:SearchControl.ColumnProvider>
                <dxe:SelectorEditColumnProvider>
                    <dxe:SelectorEditColumnProvider.CustomColumns>
                        <sys:String>Name</sys:String>
                    </dxe:SelectorEditColumnProvider.CustomColumns>
                </dxe:SelectorEditColumnProvider>
            </dxe:SearchControl.ColumnProvider>
        </dxe:SearchControl>

        <dxe:ListBoxEdit Name="listBox" Grid.Row="1"  Margin="10"
                         HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
                         DisplayMember="Name" ValueMember="ID"
                         FilterCriteria="{Binding FilterCriteria, ElementName=searchControl}">

        </dxe:ListBoxEdit>
    </Grid>
</Window>
See Also