Fixes to listview selected items

Previously SelectedIndices would continue to reference indices which no
longer existed if they were removed from the list.
This commit is contained in:
Robin 2015-12-13 00:33:39 +00:00
parent 1d16b6e5a7
commit 25495cf77e

View File

@ -125,13 +125,24 @@ namespace DarkUI.Controls
// Find the starting index of the old item list and update anything past that // Find the starting index of the old item list and update anything past that
if (e.OldStartingIndex < (Items.Count - 1)) if (e.OldStartingIndex < (Items.Count - 1))
{ {
for (var i = e.NewStartingIndex; i <= Items.Count - 1; i++) for (var i = e.OldStartingIndex; i <= Items.Count - 1; i++)
{ {
UpdateItemPosition(Items[i], i); UpdateItemPosition(Items[i], i);
} }
} }
} }
if (Items.Count == 0)
{
if (_selectedIndices.Count > 0)
{
_selectedIndices.Clear();
if (SelectedIndicesChanged != null)
SelectedIndicesChanged(this, null);
}
}
UpdateContentSize(); UpdateContentSize();
} }
@ -225,15 +236,7 @@ namespace DarkUI.Controls
public int GetItemIndex(DarkListItem item) public int GetItemIndex(DarkListItem item)
{ {
var index = -1; return Items.IndexOf(item);
foreach (var otherItem in Items)
{
index++;
if (item == otherItem)
break;
}
return index;
} }
public void SelectItem(int index) public void SelectItem(int index)