Back to Devexpress

ListBoxEdit.FilterCriteria Property

wpf-devexpress-dot-xpf-dot-editors-dot-listboxedit-0d326cf8.md

latest4.6 KB
Original Source

ListBoxEdit.FilterCriteria Property

Gets or sets the filter expression applied to the ListBoxEdit.ItemsSource. This is a dependency property.

Namespace : DevExpress.Xpf.Editors

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

NuGet Package : DevExpress.Wpf.Core

Declaration

csharp
public CriteriaOperator FilterCriteria { get; set; }
vb
Public Property FilterCriteria As CriteriaOperator

Property Value

TypeDescription
CriteriaOperator

A CriteriaOperator descendant that represents the filter expression.

|

Remarks

The ListBoxEdit control can filter an ItemSource data before the control displaying. Set the Filter Expression using the FilterCriteria property to do this.

Depending on an Item Source type, there are two approaches to create a filter expression:

  • Use the DisplayColumn value when the editor’s ItemSource is a simple type objects collection (string, byte, bool, int, etc.):

  • Use the FilterCriteria property when the editor’s ItemSource is a complex type object (it has its own properties), for example: Contains([PropertyName], '123'). The code snippet below shows how to apply the EndsWith([CategoryName], 'es') filter criteria:

For more information on how to create filter expressions, see Criteria Language Syntax and Creating Criteria.

Example

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.

xaml
<Window x:Class="ListBoxFilteringUsingSearchPanel.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:sys="clr-namespace:System;assembly=mscorlib"
        Title="MainWindow" Height="350" Width="525">
    <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>
csharp
using System.Windows;

namespace ListBoxFilteringUsingSearchPanel {
    public partial class MainWindow : Window {
        public MainWindow() {
            InitializeComponent();
            listBox.ItemsSource = Staff.GetStaff();
        }
    }
}
vb
Imports System.Windows

Namespace ListBoxFilteringUsingSearchPanel

    Public Partial Class MainWindow
        Inherits Window

        Public Sub New()
            Me.InitializeComponent()
            Me.listBox.ItemsSource = GetStaff()
        End Sub
    End Class
End Namespace

See Also

ListBoxEdit Class

ListBoxEdit Members

DevExpress.Xpf.Editors Namespace