New to Telerik UI for WinFormsStart a free 30-day trial

Inserting a Message at a Specific Index in RadChat

Updated over 6 months ago

Environment

Product VersionProductAuthor
2025.3.812RadChat for WinFormsDinko 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