At startup, I am adding the last x number of messages, but the control doesn't scroll to the bottom. How can I ensure the last message is visible?
Also, the last x messages span across more than 1 day, but my time separator always says Today.
The date in the ChatTextMessage constructor looks correct, and it is adding separators between the dates, but they all say Today
Thanks!
12 Answers, 1 is accepted
If you add the items at runtime the control will scroll to the last message. If you want you can manually do this as well (again at runtime because the items size is determined dynamically):
protected
override
void
OnShown(EventArgs e)
{
base
.OnShown(e);
RadScrollBarElement scrollbar = radChat1.ChatElement.MessagesViewElement.Scroller.Scrollbar;
scrollbar.Value = 0;
while
(scrollbar.Value < scrollbar.Maximum - scrollbar.LargeChange + 1)
{
scrollbar.PerformSmallIncrement(1);
radChat1.ChatElement.MessagesViewElement.Scroller.UpdateScrollRange();
Application.DoEvents();
}
scrollbar.PerformLast();
}
The second case is an issue. I have logged this issue on our Feedback Portal. You can track its progress, subscribe to status changes and add your comment to it here. I have also updated your Telerik Points.
To workaround this you can manually add the separators. Here is an example:
this
.radChat1.ChatElement.MessagesViewElement.TimeSeparatorInterval = TimeSpan.Zero;
var a =
new
Author(
null
,
"Test"
);
for
(
int
i = 0; i < 20; i++)
{
radChat1.AddMessage(
new
ChatTextMessage(
"Item"
+ i, a, DateTime.Now.AddDays(-(20 - i))));
ChatTimeSeparatorDataItem separator =
new
ChatTimeSeparatorDataItem(
new
ChatTimeSeparatorMessage(DateTime.Now.AddDays(-(20 - i))));
radChat1.ChatElement.MessagesViewElement.Items.Add(separator);
}
Should you have any other questions do not hesitate to ask.
Regards,
Dimitar
Progress TelerikRadChat for Winforms
is there a way to specify format of timeseparator?
using the above workaround, I am able to get separators in the right places, but date formats are wacky. (have day of week, day, year... but no month. I am manually adding chat messages from a database table and a conversation may span over several months
You can use the ItemFormatting event to access the time separators and set the format. Here is the code:
private
void
RadChat1_ItemFormatting(
object
sender, ChatItemElementEventArgs e)
{
var item = e.ItemElement
as
ChatTimeSeparatorItemElement;
if
(item !=
null
)
{
var value = item.Data
as
ChatTimeSeparatorDataItem;
item.Text = value.TiemSeparatorMessage.TimeStamp.ToShortDateString();
}
}
Should you have any other questions do not hesitate to ask.
Regards,
Dimitar
Progress TelerikRadChat for Winforms
The following code shows how you can create a context menu and copy the message:
Point location;
RadContextMenu menu =
new
RadContextMenu();
protected
override
void
OnLoad(EventArgs e)
{
base
.OnLoad(e);
var copyItem =
new
RadMenuItem(
"Copy"
);
menu.Items.Add(copyItem);
copyItem.Click += CopyItem_Click;
radChat1.MouseDown += MessagesViewElement_MouseDown;
}
private
void
MessagesViewElement_MouseDown(
object
sender, MouseEventArgs e)
{
if
(e.Button== MouseButtons.Right)
{
location = e.Location;
menu.Show(radChat1, e.Location);
}
}
private
void
CopyItem_Click(
object
sender, EventArgs e)
{
var element = radChat1.ElementTree.GetElementAtPoint(location)
as
ChatMessageBubbleElement;
if
(element !=
null
)
{
Clipboard.SetText(element.Text);
}
}
I hope this will be useful. Let me know if you have additional questions.
Regards,
Dimitar
Progress TelerikRadChat for Winforms
Wow! You're awesome dude. Thanks so much. Please don't mind i have one more question.
I got the way to copy the text message becoz of you and now i want to know
If i add ChatMediaMessage (with an image) so how can i Save that image to my Drive by using the same method (with context menu).
I know its easy for you. Thank you so much for your reply Sir.
Ragards
Kabir
You can use the same approach, here is the code:
private
void
SaveAsItem_Click(
object
sender, EventArgs e)
{
var element = radChat1.ElementTree.GetElementAtPoint(location)
as
ChatMessageBubbleElement;
if
(element !=
null
)
{
var image = element.Image;
image.Save(@
"D:\image1.png"
);
}
}
Should you have any other questions do not hesitate to ask.
Regards,
Dimitar
Progress TelerikRadChat for Winforms
Hello Sir,
I have a question.
I want to clear all chats from RadChat but i don't know how.
Please can you tell me, Sir.
Thank you.
You can hide the overlay, suggested actions and the actual messages this way:
this
.radChat1.HideOverlay();
this
.radChat1.ChatElement.SuggestedActionsElement.ClearActions();
this
.radChat1.ChatElement.MessagesViewElement.Items.Clear();
I hope this will help.
Regards,
Hristo
Progress TelerikRadChat for Winforms
Thank you Sir.
Its working. Thank u.