# Condition Class

> An object of the Condition class is an element of the ConditionalInstruction class and represents the state of a FormField that has to be fulfilled to execute the instructions of the related ConditionalInstruction object. The number of conditions inside a ConditionalInstruction object is not limited. If the ConditionalInstruction.Conditions property contains more than one element, each subsequent Condition object is connected to the previous one by an AND or OR logical connective. That implies that all these conditions are considered as a whole when the conditional instruction is tested whether or not the requirements to execute its instructions are fulfilled.

- **Product:** TX Text Control .NET for Windows Forms
- **Section:** Reference
- **Kind:** Class
- **Introduced:** 28.0
- **Namespace:** `TXTextControl`
- **Package:** `TXTextControl.TextControl.WinForms.SDK` (assembly `TXTextControl.dll`, from the private NuGet feed or Text Control Offline Packages)
- **.NET Framework:** reference `TXTextControl.dll` from the setup
- **Implements:** `System.IComparable`
- **Path:** TX Text Control .NET for Windows Forms > Reference > TXTextControl > Condition Class
- **2166 words**
- **Web URL:** https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/condition/
- **LLMs URL:** https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/condition/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/condition/llms-full.txt

---

### Description

An object of the Condition class is an [element](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/conditionalinstruction/conditions-property/llms-full.txt) of the [ConditionalInstruction](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/conditionalinstruction/llms-full.txt) class and represents the state of a [FormField](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/formfield/llms-full.txt) that has to be fulfilled to execute the [instructions](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/conditionalinstruction/instructions-property/llms-full.txt) of the related [ConditionalInstruction](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/conditionalinstruction/llms-full.txt) object. The number of conditions inside a `ConditionalInstruction` object is not limited. If the `ConditionalInstruction.Conditions` property contains more than one element, each subsequent `Condition` object is connected to the previous one by an `AND` or `OR` [logical connective](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/condition/logicalconnective-property/llms-full.txt). That implies that all these conditions are considered as a whole when the conditional instruction is tested whether or not the requirements to execute its instructions are fulfilled.

To create a condition, the `Condition` object has to be initialized with a `FormField` that is located inside the document. That `FormField` provides the value to be tested.

Furthermore, a comparison value has to be defined by the constructor's `comparisonValue` parameter. That value is compared with the `FormField`'s value by using a specified `comparisonOperator` parameter. The way in which such a comparison is implemented depends on how the set value is [interpreted](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/condition/comparisonvaluetypes-enumeration/llms-full.txt):

• The constructor's `isChecked` parameter value of a condition that references to a `CheckFormField` represents a check state to be fulfilled. If it is set to true, the [Condition.ComparisonOperator](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/condition/comparisonoperator-property/llms-full.txt) property returns `Condition.ComparisonOperators.Is`. Otherwise `Condition.ComparisonOperators.IsNot`. In both cases the `Condition.ComparisonValue` property returns true.

• Conditions that are related to form fields of type `TextFormField` or `SelectionFormField` execute a comparison to the form field's [Text](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/textfield/text-property/llms-full.txt) property value. That text can be tested as follows: If the comparison value is set to null or an emtpy string, the condition checks whether or not any text is set. If it is a string, that is not empty, by default the value is interpreted as a custom text whose string is compared with form field's text. Alternatively, that string can be handled as a regular expression that checks whether or not the form field's text matches to its pattern. That option can be determined by setting the constructor's `textComparisonFlag` parameter to `Condition.TextComparisonFlags.Regex`.

• In addition, the text of a `SelectionFormField` object can be compared with one of its [SelectionFormField.Items](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/selectionformfield/items-property/llms-full.txt) array entries or checked whether or not the string equals to one of its [SelectionFormField.Items](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/selectionformfield/items-property/llms-full.txt) array entries. These comparison types can be determined by setting the corresponding `Condition.ItemComparisonFlags` enumeration value to the constructor's `itemComparisonFlag` parameter.

• Up to four different comparison types can be applied to compare the [Date](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/dateformfield/date-property/llms-full.txt) property of `DateFormField` objects with a specified value: If the comparison value is an object of type `System.DateTime`, the year, month and day of month is compared with the current property value. On setting an integer with an value between 1601 and 9999, the year is compared. If that value is an integer between 1 and 31, the day of the month is checked. An enumeration value of type [Condition.Month](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/condition/month-enumeration/llms-full.txt) tests the month and using a `System.DayOfWeek` enumeration value compares the day of the week. Setting null as the comparison value checks whether or not the `DateFormField.Date` property value is set.

### Syntax

```csharp
public class Condition : IComparable
```

```vbnet
Public Class Condition
    Implements IComparable
```

### Examples

The following example builds a rule around an approval check box in a fillable form.

```csharp
CheckFormField approvalField = new(false) { Name = "Approved" };
textControl.FormFields.Add(approvalField);
Condition condition = new(approvalField, true);
```

```vbnet
Dim approvalField As New CheckFormField(False) With { .Name = "Approved" }
textControl.FormFields.Add(approvalField)
Dim condition As New Condition(approvalField, True)
```

---

## In This Section

- [Condition.ComparisonOperator Property](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/condition/comparisonoperator-property/llms-full.txt): Gets the operator that is used to compare the condition's form field value with the specified comparison value.
- [Condition.ComparisonOperators Enumeration](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/condition/comparisonoperators-enumeration/llms-full.txt): Determines the comparison operator that is used to compare the condition's form field value with the specified comparison value or the interpretation of that value. The enumeration contains the following values:
- [Condition.ComparisonValue Property](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/condition/comparisonvalue-property/llms-full.txt): Gets the value that is compared with the condition's form field value.
- [Condition.ComparisonValueType Property](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/condition/comparisonvaluetype-property/llms-full.txt): Gets a value of type ComparisonValueTypes that determines how the condition's comparison value is interpreted. The returned value depends on the type of the condition's FormField, the set comparison value and/or the textComparisonFlag or itemComparisonFlag parameter that were specified on invoking an instance of the Condition class.
- [Condition.ComparisonValueTypes Enumeration](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/condition/comparisonvaluetypes-enumeration/llms-full.txt): Determines how the condition's comparison value is interpreted by the condition. The enumeration contains the following values:
- [Condition Constructor](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/condition/constructor/llms-full.txt): Initializes a new instance of the Condition class.
- [Condition.FormField Property](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/condition/formfield-property/llms-full.txt): Gets the FormField whose property value is to be compared with the condition's comparison value.
- [Condition.ItemComparisonFlags Enumeration](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/condition/itemcomparisonflags-enumeration/llms-full.txt): Determines how the specified comparison value has to be interpreted when comparing it with the SelectionFormField's Text property. The enumeration contains the following values:
- [Condition.LogicalConnective Property](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/condition/logicalconnective-property/llms-full.txt): Gets or sets a value of type Condition.LogicalConnectives that describes how the condition is related to the previous condition inside the corresponding ConditionalInstruction.Conditions array. If the condition is the first element of that array, the value of that property is ignored. The default value is LogicalConnectives.And.
- [Condition.LogicalConnectives Enumeration](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/condition/logicalconnectives-enumeration/llms-full.txt): Determines how the condition is related to the previous condition inside the corresponding ConditionalInstruction.Conditions array. The enumeration contains the following values:
- [Condition.Month Enumeration](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/condition/month-enumeration/llms-full.txt): Determines the month that is compared with the condition's form field value. This enumeration can only be used as comparison value for form fields of type DateFormField. It contains the following values:
- [Condition.TextComparisonFlags Enumeration](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/condition/textcomparisonflags-enumeration/llms-full.txt): Determines how the specified comparison value has to be interpreted when comparing it with the TextFormField's or SelectionFormField's Text property. The enumeration contains the following values:

---

## Nearby

- **Previous:** [CommentsDialog.FindItem Method](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/commentsdialog/finditem-method/llms-full.txt)
- **Next:** [Condition.ComparisonOperator Property](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/condition/comparisonoperator-property/llms-full.txt)
