# DocumentTargetCollection.GetItem Method

> Gets a particular document target from the collection.

- **Product:** TX Text Control .NET for Windows Forms
- **Section:** Reference
- **Kind:** Method
- **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 > DocumentTargetCollection.GetItem Method
- **1116 words**
- **Web URL:** https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/documenttargetcollection/getitem-method/
- **LLMs URL:** https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/documenttargetcollection/getitem-method/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/documenttargetcollection/getitem-method/llms-full.txt

---

### Description

Gets a particular document target from the collection.

### Syntax

#### GetItem()

Gets the first document target at the current text input position or null if there is no document target. This method is for compatibility only with prior versions. Use [GetItems](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/documenttargetcollection/getitems-method/llms-full.txt) to get all targets at the current text input position.

```csharp
public DocumentTarget GetItem();
```

```vbnet
Public Function GetItem() As DocumentTarget
```

#### GetItem(int)

Gets the document target with the specified id, previously set with the [DocumentTarget.ID](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/documenttarget/id-property/llms-full.txt) property.

```csharp
public DocumentTarget GetItem(int id);
```

```vbnet
Public Function GetItem(id As Integer) As DocumentTarget
```

| Parameter | Description |
|---|---|
| id | Specifies the document target's identifier. The method returns null, if a document target with the specified identifier does not exist. If there are more than target with this id in the document, the first target in the document's text is returned. |

#### GetItem(string)

Gets the document target with the specified target name, previously set with the [DocumentTarget.TargetName](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/documenttarget/targetname-property/llms-full.txt) property.

```csharp
public DocumentTarget GetItem(string targetName);
```

```vbnet
Public Function GetItem(targetName As String) As DocumentTarget
```

| Parameter | Description |
|---|---|
| targetName | Specifies the document target's target name. The method returns null, if a document target with this target name does not exist. If there are more than target with this name in the document, the first target in the document's text is returned. |

### Examples

The following example works with document targets in the current document by using `DocumentTargetCollection.GetItem`.

```csharp
textControl.Text = "Customer: Contoso Ltd.";
textControl.Select(10, 12);
DocumentTargetCollection documentTargetCollection = textControl.DocumentTargets;
documentTargetCollection.Add(new DocumentTarget("CustomerDetails") { ID = 100 });

DocumentTarget result = documentTargetCollection.GetItem(100);
result?.ScrollTo();
```

```vbnet
textControl.Text = "Customer: Contoso Ltd."
textControl.Select(10, 12)
Dim documentTargetCollection As DocumentTargetCollection = textControl.DocumentTargets
documentTargetCollection.Add(New DocumentTarget("CustomerDetails") With { .ID = 100 })

Dim result As DocumentTarget = documentTargetCollection.GetItem(100)
If result IsNot Nothing Then result.ScrollTo()
```

---

## Nearby

- **Previous:** [DocumentTargetCollection.GetEnumerator Method](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/documenttargetcollection/getenumerator-method/llms-full.txt)
- **Next:** [DocumentTargetCollection.GetItems Method](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/documenttargetcollection/getitems-method/llms-full.txt)
