Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix SelectedItems NotSupportedExceptions with Linq/etc. #234

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions ImageListView/ImageListViewSelectedItemCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,12 @@ void ICollection<ImageListViewItem>.Clear()
/// <param name="arrayIndex">The zero-based index in <paramref name="array"/> at which copying begins.</param>
void ICollection<ImageListViewItem>.CopyTo(ImageListViewItem[] array, int arrayIndex)
{
throw new NotSupportedException();
int i = 0;
foreach (ImageListViewItem item in this)
{
array[arrayIndex + i] = item;
i++;
}
}
/// <summary>
/// Determines the index of a specific item in the <see cref="T:System.Collections.Generic.IList`1"/>.
Expand All @@ -164,10 +169,16 @@ void ICollection<ImageListViewItem>.CopyTo(ImageListViewItem[] array, int arrayI
/// <returns>
/// The index of <paramref name="item"/> if found in the list; otherwise, -1.
/// </returns>
[Obsolete("Use ImageListViewItem.Index property instead.")]
int IList<ImageListViewItem>.IndexOf(ImageListViewItem item)
{
throw new NotSupportedException();
int i = 0;
foreach (ImageListViewItem selectedItem in this)
{
if (selectedItem == item)
return i;
i++;
}
return -1;
}
/// <summary>
/// Inserts an item to the <see cref="T:System.Collections.Generic.IList`1"/> at the specified index.
Expand Down Expand Up @@ -204,7 +215,7 @@ ImageListViewItem IList<ImageListViewItem>.this[int index]
{
get
{
throw new NotSupportedException();
return this[index];
}
set
{
Expand Down Expand Up @@ -323,4 +334,4 @@ public void Reset()
#endregion
}
}
}
}