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:
- Access the existing messages in RadChat using the
MessagesViewElement.Itemscollection. - Create a
ChatMediaMessageor another appropriate message type. - Convert the message into a
BaseChatDataItemusing theChatFactory.CreateDataItem()method. - 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);
}