Optimize comboBox item selection

The previous implementation of the comboBox resulted in the processing of all items every time. This commit optimizes this process by only dealing with visible items, thus improving efficiency. Calculations for the visible range are now included, starting from the top item and only iterating over visible items.

Signed-off-by: Ivandro Jao <ivandrofly@gmail.com>
This commit is contained in:
Ivandro Jao 2024-06-07 09:14:37 +01:00
parent 998ee5ca95
commit c8951235a2

View File

@ -1029,8 +1029,11 @@ namespace Nikse.SubtitleEdit.Controls
return;
}
var cachedCount = _listView.Items.Count;
for (var i = 0; i < cachedCount; i++)
var topItem = _listView.TopItem;
// calculate visible range
var count = Math.Min(topItem.Index + _listView.Bounds.Height / topItem.Bounds.Height, _listView.Items.Count);
for (var i = topItem.Index; i < count; i++)
{
var rectangle = _listView.GetItemRect(i);
if (rectangle.Contains(mouseArgs.Location))