New to Telerik UI for WinForms? Download free 30-day trial

Inserting a Message at a Specific Index in RadChat

Environment

Product Version Product Author
2025.3.812 RadChat for WinForms 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:


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

In this article