# ConditionalInstructionCollection.Add Method

> Inserts an instance of the class ConditionalInstruction to the collection and the document.

- **Product:** TX Text Control .NET for Windows Forms
- **Section:** Reference
- **Kind:** Method
- **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
- **Path:** TX Text Control .NET for Windows Forms > Reference > TXTextControl > ConditionalInstructionCollection.Add Method
- **1053 words**
- **Web URL:** https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/conditionalinstructioncollection/add-method/
- **LLMs URL:** https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/conditionalinstructioncollection/add-method/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/conditionalinstructioncollection/add-method/llms-full.txt

---

### Description

Inserts an instance of the class [ConditionalInstruction](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/conditionalinstruction/llms-full.txt) to the collection and the document.

### Syntax

```csharp
public bool Add(ConditionalInstruction conditionalInstruction);
```

```vbnet
Public Function Add(conditionalInstruction As ConditionalInstruction) As Boolean
```

### Parameters

| Parameter | Description |
|---|---|
| conditionalInstruction | Specifies `ConditionalInstruction` element to add. |

### Return Value

The return value is true, if the `ConditionalInstruction` could be added. Otherwise false. A `ConditionalInstruction` element won't be added, if the [TextControl.IsFormFieldValidationEnabled](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/textcontrol/isformfieldvalidationenabled-property/llms-full.txt) property is set to false or the [TextControl.EditMode](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/textcontrol/editmode-property/llms-full.txt) is set to `EditMode.ReadAndSelect` and [TextControl.DocumentPermissions.ReadOnly](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/documentpermissions/readonly-property/llms-full.txt) to true.

### Examples

The following example registers a conditional rule for an approval check box in a fillable form.

```csharp
CheckFormField approval = new(false) { Name = "Approved" };
textControl.FormFields.Add(approval);
ConditionalInstruction rule = new()
{
    Conditions = new[] { new Condition(approval, true) },
    Instructions = new[] { new Instruction(approval, Instruction.InstructionTypes.IsEnabled, true) }
};

if (!textControl.FormFields.ConditionalInstructions.Add(rule))
{
    throw new InvalidOperationException("The approval rule could not be added.");
}
```

```vbnet
Dim approval As New CheckFormField(False) With { .Name = "Approved" }
textControl.FormFields.Add(approval)
Dim rule As New ConditionalInstruction() With {
    .Conditions = New Condition() { New Condition(approval, True) },
    .Instructions = New Instruction() { New Instruction(approval, Instruction.InstructionTypes.IsEnabled, True) }
}

If Not textControl.FormFields.ConditionalInstructions.Add(rule) Then
    Throw New InvalidOperationException("The approval rule could not be added.")
End If
```

### Remarks

A `System.ArgumentException` is thrown, if the [Name](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/conditionalinstruction/name-property/llms-full.txt) property value of the added `ConditionalInstruction` object is null or already exists as the name of another `ConditionalInstruction` inside the collection. Furthermore an exception is thrown, if the `ConditionalInstruction`'s [Condtions](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/conditionalinstruction/conditions-property/llms-full.txt) or [Instructions](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/conditionalinstruction/instructions-property/llms-full.txt) properties values do not contain elements.

---

## Nearby

- **Previous:** [ConditionalInstructionCollection Class](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/conditionalinstructioncollection/llms-full.txt)
- **Next:** [ConditionalInstructionCollection.Clear Method](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/conditionalinstructioncollection/clear-method/llms-full.txt)
