-
Notifications
You must be signed in to change notification settings - Fork 5
/
ReadOnlySelectableCollection.cs
50 lines (46 loc) · 1.32 KB
/
ReadOnlySelectableCollection.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
namespace IMAPI2
{
public class ReadOnlySelectableCollection<T> : ReadOnlyCollection<T>
{
private int _selectedIndex;
public event EventHandler SelectedIndexChanged;
public int SelectedIndex
{
get { return _selectedIndex; }
set
{
if ((_selectedIndex > (this.Count-1)) || (_selectedIndex < -1))
throw new IndexOutOfRangeException("SelectedIndex must be in range (this.Count = " + this.Count.ToString() + ").");
_selectedIndex = value;
SelectedIndexChanged(this, new EventArgs());
}
}
public T SelectedItem
{
get
{
if (_selectedIndex == -1)
{
return default(T);
}
else
{
return this[_selectedIndex];
}
}
set
{
_selectedIndex = this.IndexOf(value);
}
}
public ReadOnlySelectableCollection(IList<T> list) : base(list)
{
_selectedIndex = -1;
}
}
}