Back to Devexpress

XPView.Criteria Property

xpo-devexpress-dot-xpo-dot-xpview-5b611d93.md

latest5.4 KB
Original Source

XPView.Criteria Property

Gets or sets the criteria associated with the view.

Namespace : DevExpress.Xpo

Assembly : DevExpress.Xpo.v25.2.dll

NuGet Package : DevExpress.Xpo

Declaration

csharp
[DefaultValue(null)]
public CriteriaOperator Criteria { get; set; }
vb
<DefaultValue(Nothing)>
Public Property Criteria As CriteriaOperator

Property Value

TypeDefaultDescription
CriteriaOperatornull

A CriteriaOperator descendant which represents the criteria associated with the view.

|

Remarks

Use the Criteria property to change the criteria by which the persistent objects will be filtered while the view is being loaded. Changing this property immediately refreshes the view.

For examples and additional information about filter expressions, see these help topics:

Example

The following sample code demonstrates how to display persons who are older than 30. Only those persistent objects whose Age property’s value is greater than 30 are retrieved.

The image below shows the result.

csharp
using DevExpress.Xpo;
using DevExpress.Data.Filtering;
// ...
class SampleTable : XPBaseObject {
    private int id;
    private string name;
    private int age;

    SampleTable(Session session) : base(session) {
        this.name = "John";
        this.age = 25;
    }

    [Key(true)]
    public int ID {
        get { return id; }
        set { SetPropertyValue<int>(nameof(ID), id, value); }
    }

    public string Name {
        get { return name; }
        set { SetPropertyValue<string>(nameof(Name), name, value); }
    }

    public int Age {
        get { return age; }
        set { SetPropertyValue<int>(nameof(Age), age, value); }
    }
}

// ...

xpView1.Criteria = CriteriaOperator.Parse("Age > 30", null);
vb
Imports DevExpress.Xpo
Imports DevExpress.Data.Filtering
' ...
Class SampleTable
   Inherits XPBaseObject
   Private _id As Integer
   Private _name As String
   Private _age As Integer

   Public Sub New(ByVal _session As Session)
      MyBase.New(_session)
      Me._name = "John"
      Me._age = 25
   End Sub

   <Key(True)> _
   Public Property ID() As Integer
      Get
         Return _id
      End Get
      Set(ByVal Value As Integer)
         SetPropertyValue(Of Integer)(NameOf(FullName), _id, Value)
      End Set
   End Property

   Public Property Name() As String
      Get
         Return _name
      End Get
      Set(ByVal Value As String)
         SetPropertyValue(Of String)(NameOf(Name), _name, Value)
      End Set
   End Property

   Public Property Age() As Integer
      Get
         Return _age
      End Get
      Set(ByVal Value As Integer)
         SetPropertyValue(Of Integer)(NameOf(Age), _age, Value)
      End Set
   End Property
End Class

' ...

XpView1.Criteria = CriteriaOperator.Parse("Age > 30", Nothing)

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

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.

asp-net-mvc-grid-custom-binding-and-xpo/CS/XPCustomBindingExample/XPO/XpoBindingHandlers.cs#L40

csharp
XPView data = new XPView(Session, ClassInfo);
data.Criteria = CriteriaOperator.Parse(e.FilterExpression) & GetGroupFilter(e.GroupInfoList);
foreach(GridViewSummaryItemState summaryItem in e.SummaryItems) {

asp-net-mvc-grid-custom-binding-and-xpo/VB/XPCustomBindingExample/XPO/XpoBindingHandlers.vb#L40

vb
Dim data As New XPView(Session, ClassInfo)
data.Criteria = CriteriaOperator.Parse(e.FilterExpression) And GetGroupFilter(e.GroupInfoList)
For Each summaryItem As GridViewSummaryItemState In e.SummaryItems

See Also

XPView Class

XPView Members

DevExpress.Xpo Namespace