public ChatMessageView(MeshNetwork network, ChatListItem chatItem) { InitializeComponent(); _network = network; _chatItem = chatItem; this.Title = _network.NetworkName; _network.MessageReceived += network_MessageReceived; _network.MessageDeliveryNotification += network_MessageDeliveryNotification; _network.PeerTyping += network_PeerTyping; if (_network.Type == MeshNetworkType.Private) { _network.OtherPeer.ProfileChanged += otherPeer_ProfileChanged; } //load stored messages int totalMessageCount = _network.GetMessageCount(); if (totalMessageCount > 0) { try { customListView1.ReplaceItems(ConvertToListViewItems(_network.GetLatestMessages(totalMessageCount, MESSAGE_COUNT_PER_SCROLL), true)); customListView1.ScrollToBottom(); } catch { } } }
private void customListView1_ScrolledNearStart(object sender, EventArgs e) { foreach (CustomListViewItem item in customListView1.Controls) { IChatMessageItem messageItem = item as IChatMessageItem; if (messageItem.Message.MessageNumber == 0) { return; } else if (messageItem.Message.MessageNumber > -1) { customListView1.InsertItemsAtTop(ConvertToListViewItems(_network.GetLatestMessages(messageItem.Message.MessageNumber, MESSAGE_COUNT_PER_SCROLL), false)); return; } } }