Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions knowledge-base/chat-insert-message-specific-index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
---
title: Inserting a Message at a Specific Index in RadChat
description: Learn how to insert a message at a specific index in the RadChat control in UI for WinForms. This guide explains how to utilize the `Insert` method with a `BaseChatDataItem`.
type: how-to
page_title: How to Insert a Message at a Specific Index in RadChat Control
meta_title: How to Insert a Message at a Specific Index in RadChat Control
slug: chat-insert-message-specific-index
tags: chat, ui-for-winforms, insert-message, basechatdataitem, messagesviewelement
res_type: kb
ticketid: 1694976
---

## Environment

|Product Version|Product|Author|
|----|----|----|
|2025.3.812|RadChat for WinForms|[Dinko Krastev](https://www.telerik.com/blogs/author/dinko-krastev)|

## Description

In this tutorial, we will demonstrate how to insert a new message at a specific index in the RadChat control.

## Solution

To insert a message at a specific index in RadChat, use the `Insert()` method with a `BaseChatDataItem`. Follow these steps:

1. Access the existing messages in RadChat using the `MessagesViewElement.Items` collection.
2. Create a `ChatMediaMessage` or another appropriate message type.
3. Convert the message into a `BaseChatDataItem` using the `ChatFactory.CreateDataItem()` method.
4. Use the `Insert()` method to place the new message at a specific index.

Here is an example:

````C#

private void InsertMediaMessageAtBeginning()
{
ChatMediaMessage mediaMessage = new ChatMediaMessage(Properties.Resources.AndrewFuller, new Size(300, 200), null, this.radChat1.Author, DateTime.Now);
BaseChatDataItem baseChatDataItem = this.radChat1.ChatElement.ChatFactory.CreateDataItem(mediaMessage);
this.radChat1.ChatElement.MessagesViewElement.Items.Insert(0, baseChatDataItem);
}

````

## See Also

* [RadChat Documentation](https://docs.telerik.com/devtools/winforms/controls/chat/overview)

* [RadChat Messages](https://docs.telerik.com/devtools/winforms/controls/chat/chat-items/messages)