This is a migrated thread and some comments may be shown as answers.

Scrolling and the time separator

12 Answers 145 Views
Conversational UI, Chat
This is a migrated thread and some comments may be shown as answers.
Ryan
Top achievements
Rank 1
Ryan asked on 12 Jun 2018, 09:49 PM

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

Sort by
0
Dimitar
Telerik team
answered on 13 Jun 2018, 11:14 AM
Hi Ryan,

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
0
Robert
Top achievements
Rank 1
answered on 04 Jul 2018, 01:17 AM

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

 

 

0
Dimitar
Telerik team
answered on 04 Jul 2018, 06:11 AM
Hi Robert,

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
0
Robert
Top achievements
Rank 1
answered on 05 Jul 2018, 01:45 PM
perfect!  Thanks Dimitar.
0
Kabir
Top achievements
Rank 1
answered on 12 Aug 2018, 12:16 PM
How can i copy the message text from Radchat chat conversation? Even i cannot add a contextmenu.
0
Dimitar
Telerik team
answered on 13 Aug 2018, 10:02 AM
Hi Kabir,

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
0
Kabir
Top achievements
Rank 1
answered on 13 Aug 2018, 12:06 PM

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

0
Dimitar
Telerik team
answered on 14 Aug 2018, 05:46 AM
Hello 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
0
Kabir
Top achievements
Rank 1
answered on 14 Aug 2018, 07:54 AM
Awesome. Thank you so much. Sir.
0
Kabir
Top achievements
Rank 1
answered on 16 Aug 2018, 03:53 PM

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.


0
Hristo
Telerik team
answered on 17 Aug 2018, 08:08 AM
Hello Kabir,

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
0
Kabir
Top achievements
Rank 1
answered on 17 Aug 2018, 10:42 AM

Thank you Sir.

Its working. Thank u.

Tags
Conversational UI, Chat
Asked by
Ryan
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Robert
Top achievements
Rank 1
Kabir
Top achievements
Rank 1
Hristo
Telerik team
Share this question
or