# HtmlEventProperties class
{: .no_toc }

The dynamic event-payload bag passed to every [**HtmlElement.AddEventListener**](/tB/Packages/tbIDE/HtmlElement.md#addeventlistener) callback. Conceptually the IDE-side equivalent of the JavaScript `Event` object --- fields like `.key`, `.target.id`, `.target.value`, `.index` are accessed dynamically through the bag's `[COMExtensible(True)]` resolution.

```tb check_build
Private Sub MyButtonClicked(ByVal eventInfo As HtmlEventProperties)
    Host.DebugConsole.PrintText "clicked: " & eventInfo.target.id
End Sub

Private Sub MyKeyUp(ByVal eventInfo As HtmlEventProperties)
    If eventInfo.key = "Enter" Then ProcessEntered(eventInfo.target.value)
End Sub
```

> [!IMPORTANT]
> This interface is **`[COMExtensible(True)]`**. Field names are resolved against the underlying event object at run time. The standard DOM event properties (`.target` → the element that fired the event; `.key`, `.code`, `.altKey`, `.ctrlKey`, `.shiftKey` for keyboard events; `.clientX`, `.clientY` for mouse events; `.index` for the IDE's listview events; …) are forwarded as-is to the JavaScript-side event object. See MDN's DOM Event documentation for the standard fields.

* TOC
{:toc}

## Custom-data fan-out from `raiseEvent()`

When inline HTML inside a tool window calls the IDE-side `raiseEvent(eventName, event, stopPropagation, ...customData)` helper, the trailing *customData* values flow through to the addin's listener as `eventInfo.customData0`, `eventInfo.customData1`, …, numerically indexed from zero. This is the mechanism the listview / virtual listview use to attach per-row context (file path, line number, …) to their item events.

```tb check_build
' Inline HTML — sample 15:
'   <div class="match" onclick="raiseEvent('onClickMatch', event, true, 'C:/file.twin', 42, 8)">…</div>

Private Sub OnClickMatch(ByVal eventInfo As HtmlEventProperties)
    Dim filePath As String = eventInfo.customData0
    Dim lineNum  As Long   = eventInfo.customData1
    Dim colNum   As Long   = eventInfo.customData2
    Host.ActiveEditors.Open filePath, lineNum, colNum
End Sub
```

## Asynchronous events (`setAsyncResult`)

Some events --- notably the virtual listview's `onAsyncGetItemHTML` --- are *asynchronous*: the IDE asks the addin to produce content for a specific argument and expects the answer back through the event object itself. The argument arrives on the event as `eventInfo.asyncArgument`, and the listener responds by calling `eventInfo.setAsyncResult(answer)`:

```tb check_build
Private Sub OnAsyncGetItemHTML(ByVal eventInfo As HtmlEventProperties)
    Dim itemIndex As Long = eventInfo.asyncArgument
    eventInfo.setAsyncResult("<div>Row " & itemIndex & "</div>")
End Sub
```

This is the standard `[COMExtensible(True)]` resolution at work --- `setAsyncResult` is not declared on the interface, it is dispatched through the dynamic mechanism just like `.key` or `.target` would be. See sample 14 (`WaynesVirtualListViewAddIn`) for the full pattern, including the cache-invalidation companion call `listview.notifyChangedItem(idx)`.

## Default member

The interface's **DefaultMember** is [**Item**](#item) --- so `eventInfo("target")` is equivalent to `eventInfo.Item("target")`. The `.target.id` shorthand desugars accordingly.

## Properties

### AsyncResultResolver
{: .no_toc }

The answer to an event that the IDE waits for: the requests of a [datasheet](/tB/Packages/tbIDE/Datasheet.md). **As** **IAsyncResultResolver**, read-only. Its one method, **Resolve**, gives the answer:

Syntax: *eventInfo*.**AsyncResultResolver.Resolve** *retval*

*retval*
: *required* The answer. **Variant**; a datasheet takes a **String** of JSON.

The handler may call **Resolve** before it returns, or keep the resolver and call it later, from another thread or a timer. The handler of a datasheet's `onGetRows` in Sample 27 gives the resolver to a worker thread, which reads the rows from the database and resolves with them:

```tb check_build
Private Sub OnGetInfo(ByVal e As HtmlEventProperties)
    e.AsyncResultResolver.Resolve "{""recordCount"": 0, ""columns"": []}"
End Sub
```

An event of a virtual listview, `onAsyncGetItemHTML`, is answered with `setAsyncResult` instead; see [Asynchronous events](#asynchronous-events-setasyncresult).

### Item
{: .no_toc }

Looks up a field by name. Returns an [**HtmlEventProperty**](/tB/Packages/tbIDE/HtmlEventProperty.md), which includes the field's value plus a nested [**Properties**](/tB/Packages/tbIDE/HtmlEventProperty.md#properties) for further drill-down.

Syntax: *eventInfo*( *DomPropertyName* ) **As** [**HtmlEventProperty**](/tB/Packages/tbIDE/HtmlEventProperty.md)

*DomPropertyName*
: *required* The field name. **String**.
