# TaskBoard Events

This article describes the available events in the Telerik TaskBoard for Blazor:

* [`OnCardClick`](https://www.telerik.com/blazor-ui/documentation/components/taskboard/events#oncardclick)
* [`OnCardCreate`](https://www.telerik.com/blazor-ui/documentation/components/taskboard/events#oncardcreate)
* [`OnCardDelete`](https://www.telerik.com/blazor-ui/documentation/components/taskboard/events#oncarddelete)
* [`OnCardMove`](https://www.telerik.com/blazor-ui/documentation/components/taskboard/events#oncardmove)
* [`OnCardUpdate`](https://www.telerik.com/blazor-ui/documentation/components/taskboard/events#oncardupdate)
* [`OnColumnCreate`](https://www.telerik.com/blazor-ui/documentation/components/taskboard/events#oncolumncreate)
* [`OnColumnDelete`](https://www.telerik.com/blazor-ui/documentation/components/taskboard/events#oncolumndelete)
* [`OnColumnReorder`](https://www.telerik.com/blazor-ui/documentation/components/taskboard/events#oncolumnreorder)
* [`OnColumnUpdate`](https://www.telerik.com/blazor-ui/documentation/components/taskboard/events#oncolumnupdate)
* [`SelectedCardChanged`](https://www.telerik.com/blazor-ui/documentation/components/taskboard/events#selectedcardchanged)

Most TaskBoard event arguments are generic and depend on the two TaskBoard `@typeparam` types `TItem` and `TColumn`. To overcome a Blazor framework limitation and define events with a simpler syntax, you can set `TItem` and `TColumn` explicitly as in the code snippets below.

## OnCardClick

The TaskBoard `OnCardClick` event fires when the user:

* Clicks or taps a Card.
* Hits `Enter` while a Card is focused.

The event handler receives a generic [`TaskBoardCardClickEventArgs<TItem>`](https://www.telerik.com/blazor-ui/documentation/api/telerik.blazor.components.taskboardcardclickeventargs-1) argument.

`OnCardClick` fires after [`SelectedCardChanged`](https://www.telerik.com/blazor-ui/documentation/components/taskboard/events#selectedcardchanged).

> caption Using the TaskBoard OnCardClick event

```RAZOR.skip-repl
<TelerikTaskBoard OnCardClick="@OnTaskBoardCardClick"
                  TItem="@TaskBoardCard" />

@code {
    private void OnTaskBoardCardClick(TaskBoardCardClickEventArgs<TaskBoardCard> args)
    {
        TaskBoardCard clickedCard = args.Item;
    }
}
```

Also see the [runnable example](https://www.telerik.com/blazor-ui/documentation/components/taskboard/events#example) below.

## OnCardCreate

The TaskBoard `OnCardCreate` event fires when the user submits a new Card. The event handler receives a generic [`TaskBoardCardCreateEventArgs<TItem>`](https://www.telerik.com/blazor-ui/documentation/api/telerik.blazor.components.taskboardcardcreateeventargs-1) argument.

If the new Card should not be added, the event can be cancelled. Otherwise, the app must set a unique identifier and add the new Card to `CardData`.

```RAZOR.skip-repl
<TelerikTaskBoard CardData="@TaskBoardCards"
                  OnCardCreate="@OnTaskBoardCardCreate"
                  TItem="@TaskBoardCard" />

@code {
    private List<TaskBoardCard> TaskBoardCards { get; set; } = new();

    private void OnTaskBoardCardCreate(TaskBoardCardCreateEventArgs<TaskBoardCard> args)
    {
        //args.IsCancelled = true;

        args.Item.Id = 123;

        TaskBoardCards.Add(args.Item);
    }
}
```

Also see the [runnable example](https://www.telerik.com/blazor-ui/documentation/components/taskboard/events#example) below.

## OnCardDelete

The TaskBoard `OnCardDelete` event fires when the user clicks a Card delete button or when the app executes the [`DeleteCardAsync()` method of the `TaskBoardCardTemplateContext`](https://www.telerik.com/blazor-ui/documentation/components/taskboard/templates#cardtemplate). The event handler receives a generic [`TaskBoardCardDeleteEventArgs<TItem>`](https://www.telerik.com/blazor-ui/documentation/api/telerik.blazor.components.taskboardcarddeleteeventargs-1) argument.

If the Card should not be deleted, the event can be cancelled. Otherwise, the app must remove the Card item from `CardData`.

> caption Using the TaskBoard OnCardDelete event

```RAZOR.skip-repl
<TelerikTaskBoard CardData="@TaskBoardCards"
                  OnCardDelete="@OnTaskBoardCardDelete"
                  TItem="@TaskBoardCard" />

@code {
    private List<TaskBoardCard> TaskBoardCards { get; set; } = new();

    private void OnTaskBoardCardDelete(TaskBoardCardDeleteEventArgs<TaskBoardCard> args)
    {
        //args.IsCancelled = true;

        TaskBoardCards.Remove(args.Item);
    }
}
```

Also see the [runnable example](https://www.telerik.com/blazor-ui/documentation/components/taskboard/events#example) below.

## OnCardMove

The TaskBoard `OnCardMove` event fires when the user drags and drops a Card to another position or another column. The event handler receives a generic [`TaskBoardCardMoveEventArgs<TItem>`](https://www.telerik.com/blazor-ui/documentation/api/telerik.blazor.components.taskboardcardmoveeventargs-1) argument.

If the dragged Card should not be moved, the event can be cancelled. Otherwise, the app must update the [Card `Index` and `Status` values](https://www.telerik.com/blazor-ui/documentation/components/taskboard/data-binding#default-property-names).

> caption Using the TaskBoard OnCardMove event

```RAZOR.skip-repl
<TelerikTaskBoard OnCardMove="@OnTaskBoardCardMove"
                  TItem="@TaskBoardCard" />

@code {
    private void OnTaskBoardCardMove(TaskBoardCardMoveEventArgs<TaskBoardCard> args)
    {
        //args.IsCancelled = true;

        args.Item.Index = args.NewIndex;
        args.Item.Status = args.NewStatus;
    }
}
```

Also see the [runnable example](https://www.telerik.com/blazor-ui/documentation/components/taskboard/events#example) below.

## OnCardUpdate

The TaskBoard `OnCardUpdate` event fires when the user submits changes to an existing Card. The event handler receives a generic [`TaskBoardCardUpdateEventArgs<TItem>`](https://www.telerik.com/blazor-ui/documentation/api/telerik.blazor.components.taskboardcardupdateeventargs-1) argument, which exposes a cloned modified copy of the edited Card.

If the Card should not be modified, the event can be cancelled. Otherwise, the app must apply the changes to the original Card item in `CardData`.

> caption Using the TaskBoard OnCardUpdate event

```RAZOR.skip-repl
<TelerikTaskBoard OnCardUpdate="@OnTaskBoardCardUpdate"
                  TItem="@TaskBoardCard" />

@code {
    private void OnTaskBoardCardUpdate(TaskBoardCardUpdateEventArgs<TaskBoardCard> args)
    {
        //args.IsCancelled = true;

        args.OriginalItem.Description = args.Item.Description;
        args.OriginalItem.Title = args.Item.Title;
    }
}
```

Also see the [runnable example](https://www.telerik.com/blazor-ui/documentation/components/taskboard/events#example) below.

## OnColumnCreate

The TaskBoard `OnColumnCreate` event fires when the user clicks the [`TaskBoardToolBarAddColumnTool`](https://www.telerik.com/blazor-ui/documentation/components/taskboard/toolbar#built-in-tools) in the [TaskBoard ToolBar](https://www.telerik.com/blazor-ui/documentation/components/taskboard/toolbar). The event handler receives a generic [`TaskBoardColumnCreateEventArgs<TColumn>`](https://www.telerik.com/blazor-ui/documentation/api/telerik.blazor.components.taskboardcolumncreateeventargs-1) argument that allows you to set Column properties. The new Column automatically displays in edit mode, so that the user can fill in the `Title` property.

If the new Column should not be added, the event can be cancelled. Otherwise, the app must add the new Column to `ColumnData`. Optionally, set a unique `Status` or the component will assign one automatically.

> caption Using the TaskBoard OnColumnCreate event

```RAZOR.skip-repl
<TelerikTaskBoard ColumnData="@TaskBoardColumns"
                  OnColumnCreate="@OnTaskBoardColumnCreate"
                  TColumn="@TaskBoardColumn" />

@code {
    private List<TaskBoardColumn> TaskBoardColumns { get; set; } = new();

    private void OnTaskBoardColumnCreate(TaskBoardColumnCreateEventArgs<TaskBoardColumn> args)
    {
        //args.IsCancelled = true;

        //args.Item.Status = "status-123";

        TaskBoardColumns.Add(args.Item);
    }
}
```

Also see the [runnable example](https://www.telerik.com/blazor-ui/documentation/components/taskboard/events#example) below.

## OnColumnDelete

The TaskBoard `OnColumnDelete` event fires when the user clicks the `DeleteColumn` button in the Column header. The event handler receives a generic [`TaskBoardColumnDeleteEventArgs<TColumn>`](https://www.telerik.com/blazor-ui/documentation/api/telerik.blazor.components.taskboardcolumndeleteeventargs-1) argument.

If the Column should not be deleted, the event can be cancelled. Otherwise, the app must remove the Column item from `ColumnData`. The app can also delete all Cards from the non-existent column or change their `Status` to move them to another column.

> caption Using the TaskBoard OnColumnDelete event

```RAZOR.skip-repl
<TelerikTaskBoard CardData="@TaskBoardCards"
                  ColumnData="@TaskBoardColumns"
                  OnColumnDelete="@OnTaskBoardColumnDelete"
                  TColumn="@TaskBoardColumn" />

@code {
    private List<TaskBoardColumn> TaskBoardColumns { get; set; } = new();

    private void OnTaskBoardColumnDelete(TaskBoardColumnDeleteEventArgs<TaskBoardColumn> args)
    {
        //args.IsCancelled = true;

        TaskBoardColumns.Remove(args.Item);

        // Optionally, delete or move all Cards from the column
        TaskBoardCards.RemoveAll(c => c.Status == args.Item.Status);
    }
}
```

Also see the [runnable example](https://www.telerik.com/blazor-ui/documentation/components/taskboard/events#example) below.

## OnColumnReorder

The TaskBoard `OnColumnReorder` event fires when the user drags a column to another position. The event handler receives a generic [`TaskBoardColumnReorderEventArgs<TColumn>`](https://www.telerik.com/blazor-ui/documentation/api/telerik.blazor.components.taskboardcolumnreordereventargs-1) argument that exposes information about the dragged column and its old and new order index. The `ColumnData` collection updates automatically, but you may need to update the original data source in order to persist the change for other users and future sessions. If the Column should not be moved, cancel the event.

> caption Using the TaskBoard OnColumnReorder event

```RAZOR.skip-repl
<TelerikTaskBoard ColumnReorderable="true"
                  OnColumnReorder="@OnTaskBoardColumnReorder"
                  TColumn="@TaskBoardColumn" />

@code {
    private void OnTaskBoardColumnReorder(TaskBoardColumnReorderEventArgs<TaskBoardColumn> args)
    {
        // If the user action is not valid
        //args.IsCancelled = true;

        // OR

        // Update the original column data source

        Console.WriteLine($"Reordered column {args.Item.Title} from index {args.OldIndex} to index {args.NewIndex}");
    }
}
```

Also see the [runnable example](https://www.telerik.com/blazor-ui/documentation/components/taskboard/events#example) below.

## OnColumnUpdate

The TaskBoard `OnColumnUpdate` event fires when the user submits a new Column title from the built-in Column header UI. The event handler receives a generic [`TaskBoardColumnUpdateEventArgs<TColumn>`](https://www.telerik.com/blazor-ui/documentation/api/telerik.blazor.components.taskboardcolumnupdateeventargs-1) argument.

If the Column title should not be modified, the event can be cancelled. Otherwise, the app must apply the changes to the original Column item.

> caption Using the TaskBoard OnColumnUpdate event

```RAZOR.skip-repl
<TelerikTaskBoard ColumnData="@TaskBoardColumns"
                  OnColumnUpdate="@OnTaskBoardColumnUpdate"
                  TColumn="@TaskBoardColumn" />

@code {
    private List<TaskBoardColumn> TaskBoardColumns { get; set; } = new();

    private void OnTaskBoardColumnUpdate(TaskBoardColumnUpdateEventArgs<TaskBoardColumn> args)
    {
        //args.IsCancelled = true;

        args.OriginalItem.Title = args.Item.Title;
    }
}
```

Also see the [runnable example](https://www.telerik.com/blazor-ui/documentation/components/taskboard/events#example) below.

## SelectedCardChanged

The TaskBoard `SelectedCardChanged` event fires when the user selects a card. Use the event if you need to execute related custom logic. Make sure to update the value of the `SelectedCard` parameter in the event handler.

The event handler receives a `Nullable<TItem>` argument that is the newly selected Card.

`SelectedCardChanged` fires before [`OnCardClick`](https://www.telerik.com/blazor-ui/documentation/components/taskboard/events#oncardclick).

```RAZOR.skip-repl
<TelerikTaskBoard SelectedCard="@TaskBoardSelectedCard"
                  SelectedCardChanged="@TaskBoardSelectedCardChanged" />

@code {
    private TaskBoardCard? TaskBoardSelectedCard { get; set; }

    private void TaskBoardSelectedCardChanged(TaskBoardCard? newSelectedCard)
    {
        TaskBoardSelectedCard = newSelectedCard;
    }
}
```

## Example

> caption Using the TaskBoard events

<demo metaUrl="client/taskboard/events/example-1/" height="550"></demo>

## See Also

* [TaskBoard Data Binding](https://www.telerik.com/blazor-ui/documentation/components/taskboard/data-binding)
* [TaskBoard Templates](https://www.telerik.com/blazor-ui/documentation/components/taskboard/templates)
* [TaskBoard API Reference](https://www.telerik.com/blazor-ui/documentation/api/telerik.blazor.components.teleriktaskboard-2)
