# SmartDataEntryAdapter

## Overview

The SmartDataEntry adapter enhances all controls within supported containers—including GroupBox, Panel, Form, Page, and UserControl—with automatic data extraction capabilities powered by AI. This means that all controls inside these containers benefit from intelligent data entry features, significantly improving efficiency and accuracy in data handling within your applications.

The SmartDataEntry adapter operates by introducing design-time properties to all controls within a container. To utilize this functionality, the first step is to associate the adapter with a specific container (see [Adding AI Features to Your Application](/ai/concepts/getting-started.md#adding-ai-features-to-your-application)). Once this association is established, every child control within the container will display three new AI properties: FieldName, FieldPrompt, and FieldRectangle.

These properties are analogous to the FieldName, FieldPrompt, and FieldRectangle attributes employed by the [SmartObjectAdapter](/ai/components/adapters/smartobjectadapter.md).

Use the properties FieldName, FieldPrompt, and FieldRectangle to help the AI model identify what type of data to extract and the process for doing it.

For example, the design properties below illustrate how `textBox6` is set up to automatically extract the "Website URL" from unstructured data. Additionally, if the URL is missing, it can deduce it from other available information.

<figure><img src="/files/OtM6bspxAoELRZjMimFr" alt=""><figcaption></figcaption></figure>

To use this adapter, you have access to a few straightforward [methods](#methods) to initiate the extraction process. These methods can extract data from text, an image, a stream (which may contain either a document or an image), and from the clipboard (which can contain text or an image).

{% hint style="success" %}
The adapter also supports tabular data, allowing you to set FieldName and FieldPrompt on a DataGridView as well as on each individual column.
{% endhint %}

&#x20;The supported controls include:

* CheckBox
* RadioButton
* NumericUpDown
* TrackBar
* ProgressBar
* ListBox
* DataGridView (DataGridColumn)
* ComboBox
* TextBox
* Any other control that has a Text property

When populating a DataGridView, the adapter can either create new rows directly within the DataGridView or fill data into the associated DataSource.

{% hint style="danger" %}
Please note that currently, ListView and DataRepeater controls are not supported by the adapter.
{% endhint %}

### Configuration

```csharp
[Extends(typeof(Panel), allowMultiple: true)]
[Extends(typeof(GroupBox), allowMultiple: true)]
[Extends(typeof(ContainerControl), allowMultiple: true)]
```

## Properties

In addition to the properties inherited from the [SmartAdapter](/ai/components/adapters/smartadapter.md), the SmartDataEntryAdapter exposes the following additional properties.

### UseOCR

The **UseOCR** property determines whether Optical Character Recognition (OCR) service should be used for processing images. When this property is set to true, Wisej.AI utilizes the [IOCRService](/ai/components/api/services/iocrservice.md) to carry out OCR operations, with the [DefaultOCRService](/ai/components/api/services/iocrservice/wisej.ai.services.defaultocrservice.md) implementation leveraging Wisej.NET's Tesseract extension to perform OCR directly in the user's browser.

Conversely, when UseOCR is set to false, which is the default setting, the image data is forwarded to the AI model, which is expected to possess vision capabilities to handle the image processing tasks.

{% hint style="warning" %}
When utilizing the built-in OCR service, please be aware that its default language setting is "eng" (English). For instructions on how to modify the OCR language, refer to the [Language](/ai/components/built-in-services/iocrservice.md#language) section of the documentation.
{% endhint %}

### ExcludeReadOnly

When ExcludeReadOnly is set to true, any control with the ReadOnly property enabled will be bypassed during the data extraction process.

## Extender Properties

All the extender properties are optional. Wisej.AI can use the control name, if descriptive enough, without additional information.

### FieldName

Assigns a specific name to the field for the data extraction prompt. This is important for clarifying the purpose of a field. For instance, consider fields named `nameTextBox`, `textBoxName`, or `tbName`. The label "Name" can be ambiguous, potentially referring to a first name, last name, or a full name. By setting the FieldName property to something explicit like "First Name," you help the AI model accurately identify and assign the correct data to the field.

### FieldPrompt

FieldPrompt contains additional instructions for the model concerning the control. For example, when extracting a phone number, you can specify the desired format ("Always use (999) 999-9999") or provide instructions to help the AI pinpoint the data ("The reference appears after Your Ref: or just Ref:"). These instructions enhance the AI's ability to accurately format and isolate the correct data.

### FieldRectangle

FieldRectangle is applicable only when extracting data from an image. It defines an optional rectangle used to crop the image, assisting the AI model in concentrating on a specific area. The rectangle can be configured using the built-in editor provided below.

<figure><img src="/files/sWYLlDay2GP8WrLI52Pz" alt=""><figcaption></figcaption></figure>

{% hint style="success" %}
You can use the same rectangle for multiple fields. Wisej.AI internally groups controls sharing the same rectangle and optimizes the requests to the AI model.
{% endhint %}

## Methods

### FromTextAsync

This function fills the "smart" controls from the given text.

```csharp
var invoice = await adapter.FromTextAsync<invoice>(text);

// or

var invoice = (Invoice)(await adapter.FromTextAsync(text, typeof(Invoice));)
```

### FromImageAsync

This function fills the "smart" controls from the specified image.

```csharp
var invoice = await adapter.FromImageAsync<invoice>(image);

// or

var invoice = (Invoice)(await adapter.FromImageAsync(image, typeof(Invoice));)
```

### FromStreamAsync

This function fills the "smart" controls the specified stream.

The final parameter is the content type, and it is optional. If not specified, Wisej.AI will attempt to autodetect the content type from the following options: PDF, PNG, JPG, BMP, GIF, and DOCX. If autodetection fails, it will default to TXT.

{% code overflow="wrap" %}

```csharp
var invoice = await adapter.FromStreamAsync<invoice>(File.OpenRead("Invoice.pdf"));
var invoice = await adapter.FromStreamAsync<invoice>(File.OpenRead("Invoice.pdf"), ".pdf");

// or

var invoice = (Invoice)(await adapter.FromStreamAsync(image, typeof(Invoice), File.OpenRead("Invoice.pdf"));)
```

{% endcode %}

### FromClipboardAsync

This function fills the "smart" controls from the content of the clipboard. It supports both text and image conversions.

```csharp
var invoice = await adapter.FromClipboardAsync<invoice>();

// or

var invoice = (Invoice)(await adapter.FromClipboardAsync(typeof(Invoice));)
```

{% hint style="warning" %}
Please be aware that the web page must be in focus for the browser to access and read the clipboard contents.
{% endhint %}

## Events

### ParseValue

This event is triggered once the AI model has successfully extracted all values from the input unstructured data, but before it attempts at converting the value to match the `DesiredType`. It provides the application an opportunity to inspect and modify the extracted values if necessary.

<table><thead><tr><th width="132" valign="top">Name</th><th>Description</th></tr></thead><tbody><tr><td valign="top">e.Value</td><td>The value extracted by the AI model. You can change it handling this event.</td></tr><tr><td valign="top">e.Control</td><td>The control that will be assigned the parsed value.</td></tr><tr><td valign="top">e.DesiredType</td><td>The desired type of the parsed value.</td></tr></tbody></table>

### UpdateField

This event is triggered before the adapter assigns a value to the control. By handling this event and setting `e.Handle` to `true`, you can override the default behavior and take control of updating the control manually.

<table><thead><tr><th width="132" valign="top">Name</th><th>Description</th></tr></thead><tbody><tr><td valign="top">e.Value</td><td>The value to be assigned to the e.Control. Read only.</td></tr><tr><td valign="top">e.Control</td><td>The control that is about to receive the e.Value. Read only.</td></tr></tbody></table>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.wisej.com/ai/components/adapters/smartdataentryadapter.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
